title: whenever i am saving datagridview it saves all the records , even if they are in SQL table. how can I prevent this?
body: <p>whenever i am saving data of gridview it saves all the data not that rows which are inserted </p>
  
  <pre><code>            using (SqlConnection con = new SqlConnection(conn))
              {
                  string query = "INSERT INTO dbo.[Ledger_" + tbpg.Text + "] VALUES(@Sno, @Date, @Particulars, @Credit, @Debit, @Balance)";
                  query += "DELETE FROM dbo.[Ledger_"+tbpg.Text+"] WHERE Date IS NULL;";
                  using (SqlCommand cmd = new SqlCommand(query, con))
                  {
  
                      cmd.Parameters.Add("@Sno", SqlDbType.Int).Value = row.Cells["Sno"].Value ?? (object)DBNull.Value;
                      cmd.Parameters.Add("@Date", SqlDbType.Date).Value = row.Cells["Date"].Value ?? (object)DBNull.Value;
                      cmd.Parameters.Add("@Particulars", SqlDbType.VarChar).Value = row.Cells["Particulars"].Value ?? (object)DBNull.Value;
                      cmd.Parameters.Add("@Credit", SqlDbType.Int).Value =  row.Cells["Credit"].Value ?? (object)DBNull.Value;
                      cmd.Parameters.Add("@Debit", SqlDbType.Int).Value = row.Cells["Debit"].Value ?? (object)DBNull.Value;
                      cmd.Parameters.Add("@Balance", SqlDbType.Int).Value = row.Cells["Balance"].Value ?? (object)DBNull.Value;
  
  
  
  
                      con.Open();
                      cmd.ExecuteNonQuery();
                      con.Close();
                  }
              }
  </code></pre>