title: Insert all data of a datagridview to database at once
body: <p>I have a datagridview which is created by various action and user's manipulation of data.
  I want to insert all the data of the gridview to the database at once, I know I could try a code similar to this: </p>
  
  <pre><code>for(int i=0; i&lt; dataGridView1.Rows.Count;i++)
      {
          string StrQuery= @"INSERT INTO tableName VALUES (" + dataGridView1.Rows[i].Cells["ColumnName"].Value +", " + dataGridView1.Rows[i].Cells["ColumnName"].Value +");";
  
        try
        {
          using (SqlConnection conn = new SqlConnection(ConnString))
          {
              using (SqlCommand comm = new SqlCommand(StrQuery, conn))
              {
                  conn.Open();
                  comm.ExecuteNonQuery();
              }
          }
        }
  </code></pre>
  
  <p>But will it be fair to create a new connection every time a record is inserted? The datagrid may contain many rows... Is there any way to take off all the data to the server at once and loop inside in sql to insert all the data?</p>