I refactored your code a little bit: the SqlCommand has to be executed for each rows, and the parameters have to be retrieve from the GridView before.
conn.Open();
using(SqlCommand cmd = new SqlCommand(sql, conn))
{
var now = DateTime.Now;
foreach (GridViewRow row in GridView1.Rows)
{
string myPart = row.Cells[0].Text;
string myQuantity = row.Cells[1].Text;
string myPrice = row.Cells[2].Text;
//... etc
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@Item", myPart);
cmd.Parameters.AddWithValue("@Quantity", myQuantity);
cmd.Parameters.AddWithValue("@Price", myPrice);
cmd.Parameters.AddWithValue("@ModelID, methodID);
cmd.Parameters.AddWithValue("@DateCreatedOn, now);
cmd.ExecuteNonQuery();
}
}
conn.Close();
I am not sure you want to store Price, Quantity and numeric values as text. You probably want to do some validation first, and do some conversions instead of picking the Text property. What not take the .Value of the cell (if their CellValueType is defined correctly) ?