Hi all,
I am adding rows to a gridview at button click... User can add as many records to the gridview .... Now i want to add all the rows data to database in one go..
How can i do this please help
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satish BhatRank #2,496 · 563 reputationPosted Oct 1, 2011, 1:48 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Oct 1, 2011, 3:23 AM EDT
Dim hdpdtcid As New TextBox
For Each dg As GridViewRow In grdDematChk.Rows
dgqty = dg.FindControl("TextBox1")
hdpdtcid = dg.FindControl("TextBox2")
//write insert statement here you can get text as dgqty .Text
End If
Next
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 1, 2011, 4:17 AM EDT
SqlCommand cmd ;
SqlConnection oConn = new SqlConnection(" Your Connection String ");
oConn.Open();
cmd.Connection = oConn;
cmd.CommandType = CommandType.Text;
int n=0 ; //get how many rows are added at end of insert
foreach (DataRow dr in GridView1.Rows)
{
cmd = new SqlCommand("Insert Into Tablename values (@Value1, @Value2)"); //Insert Query
//Give Your Column name or use as dr.rows.cell[index]
cmd.parameter["@Value1"].value = dr["GridViewColumnName"];
cmd.parameter["@Value2"].value = dr["GridViewColumnName"];
n += cmd.ExecuteNonQuery();
cmd.parameter.clear();
}
oConn.Close();
---------------------------------------------------------------------------------------------
Thank You