if i have two items in a grid to save by using two different item id's.how can we possible to save these two at a time?in c# ,2 tier,sql 2005
example: item itemcode
tea 10
coffee 11
Save two
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 21, 2013, 1:52 AM EDT
you can try like this
protected void btninsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
con.Open();
str = "insert into itemtable(item,itemcode) values('" + row.Cells[1].Text + "','" + row.Cells[2].Text + "')";
SqlCommand com=new SqlCommand(str,con);
com.ExecuteNonQuery();
con.Close();
}
}