Israel

Israel

  • NA
  • 1.3k
  • 203.1k

Convert string to decimal number

Nov 21 2020 5:06 AM
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.
 
  1. if (conn.State != ConnectionState.Open)  
  2.                 conn.Open();  
  3.             SqlCommand comm = new SqlCommand();  
  4.             comm.Connection = conn;              
  5.             SqlParameter debit = new SqlParameter("@debit", SqlDbType.Decimal);  
  6.             SqlParameter credit = new SqlParameter("@credit", SqlDbType.Decimal);              
  7.             comm.Parameters.Add(debit);  
  8.             comm.Parameters.Add(credit);              
  9.             debit.Value = Convert.ToDecimal(txtDebit.Text, CultureInfo.InvariantCulture);  //its stucks here
  10.             credit.Value = Convert.ToDecimal(txtCredit.Text, CultureInfo.InvariantCulture);  //its stucks here
  11.             comm.Connection = conn;  
  12.   
  13.             comm.CommandText = "insert into pay ([debit],[credit])values(@debit,@credit)";             
  14.             {  
  15.                 if (MessageBox.Show("Are you sure to save?""Save", MessageBoxButtons.YesNo) == DialogResult.Yes)  
  16.                 {  
  17.                     try  
  18.                     {  
  19.                         comm.ExecuteNonQuery();                         
  20.                     }  
  21.   
  22.                     finally  
  23.                     {  
  24.                         conn.Close();  
  25. }  
 

Answers (10)