You can loop through the rows in GridView and extract each row values to be inserted.
Here's a quick example:
protected void Button1_Click(object sender, EventArgs e)
{
StringCollection sc = new StringCollection();
string field1 = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)//loop the GridView Rows{
field1 = GridView1.Rows[i].Cells[0].Text; // get the field to be Inserted
sc.Add(field1); // add the field to be Inserted in the StringCollection
}
InsertRecords(sc); // call method for insert and pass the StringCollection values
}
//Multiple Inserts
private void InsertRecords(StringCollection sc)
{
SqlConnection conn = new SqlConnection("Your Connection String");
StringBuilder sb = new StringBuilder(string.Empty);
foreach (string item in sc)
{
const string sqlStatement = "INSERT INTO TableName (ColumnName) VALUES ";
sb.AppendFormat("{0}'{1}'; ",sqlStatement, item);
}
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}