Marvin kakuru

Marvin kakuru

  • 1.3k
  • 324
  • 155k

Error converting data type varchar to numeric

Aug 12 2011 7:19 AM
hi all. ope your allright,
i am inserting into my sql database data from a datagridview1, however some of the values are numeric and i keep on getting an error - " ERROR CONVERTING DATA TYPE VARCHAR TO NUMERIC"

funny though the data is inserted into the database table, but the error remains below is the code i am using.


foreach (DataGridViewRow row in dataGridView1.Rows)
            {

                string insertString = " insert into Treatmentpurchases (day,date,month,year,wkno,drugid,drugname,drugmeasure,cost,duration) values ('" + row.Cells["Day"].Value + "' , '" + row.Cells["Date"].Value + "' , '" + row.Cells["Month"].Value + "' , '" + row.Cells["Year"].Value + "' , '" + row.Cells["Wkno"].Value + "' , '" + row.Cells["Drugid"].Value + "' , '" + row.Cells["Drug"].Value + "' , '" + row.Cells["Measure"].Value + "' , '" + row.Cells["Cost"].Value + "' , '" + row.Cells["Duration"].Value + "')";

                SqlCommand cmd = new SqlCommand(insertString, conn);
                cmd.ExecuteNonQuery();
            }


the numeric values are wkno and year. Any help???

Answers (11)