1
Answer

Datagridview

Marvin kakuru

Marvin kakuru

13y
1.9k
1
hi ALL

I am trying to insert data from datagridview to sql, but i only insert one line or one row,
below is the code i am using.

 int row = dataGridView1.Rows.Count-2;

  SqlConnection conn = new SqlConnection("Data Source=KATOTO-PC;Initial Catalog =thyfarm;User ID=sa;Password=Kyozi");

  conn.Open();

  string insertString = "insert into Treatmentpurchases (day) values ('" + dataGridView1.Rows[row].Cells["Day"].Value + "')";
  SqlCommand cmd = new SqlCommand(insertString, conn);

  cmd.ExecuteNonQuery();
  conn.Close();

any help will be highly appreciated.
Answers (1)