title: May I know how to insert new added data in DataGridView to database?
body: <p><img src="https://i.stack.imgur.com/215cX.jpg" alt="enter image description here"></p>
  
  <p>I need to know how to add the new inserted data row from <code>DataGridView</code> to database. No matter how rows have been inserted, when I click on Update Button, all the new inserted rows will be inserted into database.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>con = new System.Data.SqlClient.SqlConnection();
  con.ConnectionString = "Data Source=tcp:SHEN-PC,49172\\SQLEXPRESS;Initial Catalog=LSEStock;Integrated Security=True";
  con.Open();
  SqlDataAdapter da = new SqlDataAdapter();
  
  for (int i = 0; i&gt;=dataGridView1.Rows.Count - 1; i++ )
  {
  
      String insertData = "INSERT INTO CostList(SupplierName, CostPrice, PartsID) VALUES (@SupplierName, @CostPrice, '" + textBox1.Text + "')";
      SqlCommand cmd = new SqlCommand(insertData, con);
      cmd.Parameters.AddWithValue("@SupplierName", dataGridView1.Rows[i].Cells[0].Value);
      cmd.Parameters.AddWithValue("@CostPrice", dataGridView1.Rows[i].Cells[1].Value);
      cmd.Parameters.AddWithValue("@PartsID", textBox1.Text);
      da.InsertCommand = cmd;
      cmd.ExecuteNonQuery();
  }
  
  con.Close();
  </code></pre>
  
  <p>The above code has no respond after I clicking Update button. There is no error but nothing has been inserted in the database, the data shown in the picture is the original data that has already in my database.</p>
  
  <p>Or anyone who has a better codes to insert all the new added rows of data into database, please do let me know. I will appreciate it.</p>