Hi,
I do try many time to save decimal number into my database but there is erro saying that its cannot save string number. My database has two column (debit and credit) with number type. But when click to save its doesnt and stuck on line I coulored in red.
- if (conn.State != ConnectionState.Open)
- conn.Open();
- SqlCommand comm = new SqlCommand();
- comm.Connection = conn;
- SqlParameter debit = new SqlParameter("@debit", SqlDbType.Decimal);
- SqlParameter credit = new SqlParameter("@credit", SqlDbType.Decimal);
- comm.Parameters.Add(debit);
- comm.Parameters.Add(credit);
- debit.Value = Convert.ToDecimal(txtDebit.Text, CultureInfo.InvariantCulture); //its stucks here
- credit.Value = Convert.ToDecimal(txtCredit.Text, CultureInfo.InvariantCulture); //its stucks here
- comm.Connection = conn;
- comm.CommandText = "insert into pay ([debit],[credit])values(@debit,@credit)";
- {
- if (MessageBox.Show("Are you sure to save?", "Save", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- comm.ExecuteNonQuery();
- }
- finally
- {
- conn.Close();
- }

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 23, 2020, 9:55 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Nov 21, 2020, 12:36 AM EST
better is to use decimal as database coulmn then in your code do like belowpis the number of total digits your decimal can have.sis the max number of digits you can have after the decimal point.Nitin SontakkeRank #264 · 9.6K reputationPosted Nov 21, 2020, 1:29 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Nov 21, 2020, 12:16 AM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Nov 21, 2020, 12:18 AM EST
IsraelRank #1,223 · 1.5K reputationPosted Nov 21, 2020, 12:50 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Nov 21, 2020, 12:55 AM EST
IsraelRank #1,223 · 1.5K reputationPosted Nov 22, 2020, 11:18 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Nov 22, 2020, 11:26 PM EST
IsraelRank #1,223 · 1.5K reputationPosted Nov 24, 2020, 4:39 AM EST