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 KumarPosted Nov 24, 2020, 2:55 AM
IsraelPosted Nov 24, 2020, 9:39 AM
Sachin SinghPosted Nov 23, 2020, 4:26 AM
IsraelPosted Nov 23, 2020, 4:18 AM
Nitin SontakkePosted Nov 21, 2020, 6:29 AM
Amit GuptaPosted Nov 21, 2020, 5:55 AM
IsraelPosted Nov 21, 2020, 5:50 AM
Sachin SinghPosted Nov 21, 2020, 5:36 AM
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 SontakkePosted Nov 21, 2020, 5:18 AM
Amit GuptaPosted Nov 21, 2020, 5:16 AM