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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Sep 21, 2013, 5:52 AM
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();
}
}