inserting multiple rows at a time
-
Hi all actually on my webpage am displaying some data on the datagrid row wise...as per the project requirement am exposing the data to be editable(displaying in the text boxex) by making use of the itemtempale ...and am keeping one button outside the datagird.and while cliking on the button i am updating the entire datagrid by accepting what ever the data is modified i.e by calling like foreach(DataGridItem itm in DataGrid1.Items) { string st,st1,st2; st=((Label)itm.Cells[0].FindControl("lblAccountId")).Text; st1=((TextBox)itm.Cells[1].FindControl("AccCode")).Text; st2=((TextBox)itm.Cells[2].FindControl("Descrip")).Text; dataAdapter=new SqlDataAdapter("update AccountCode set AccountCode='" + st1 + "',Description='" + st2 + "'where AccountId=" + st,con); dataAdapter.Fill(ds,"contentTable"); } Know what the problem is...there was somany records like (100+ in the database)..if i did like this,it took a database interaction to update each row ...i.e,for the single click it will take 100+ times of database interaction... bcz of performance resion i want to avoid these interactions...i want the updation to be done by making single interaction with the database(i.e i want to handle all the datagrid data and take the updation at single time)......Plz help me out ,,or let me have some articles related to this.... regards yuva
-
Hi all actually on my webpage am displaying some data on the datagrid row wise...as per the project requirement am exposing the data to be editable(displaying in the text boxex) by making use of the itemtempale ...and am keeping one button outside the datagird.and while cliking on the button i am updating the entire datagrid by accepting what ever the data is modified i.e by calling like foreach(DataGridItem itm in DataGrid1.Items) { string st,st1,st2; st=((Label)itm.Cells[0].FindControl("lblAccountId")).Text; st1=((TextBox)itm.Cells[1].FindControl("AccCode")).Text; st2=((TextBox)itm.Cells[2].FindControl("Descrip")).Text; dataAdapter=new SqlDataAdapter("update AccountCode set AccountCode='" + st1 + "',Description='" + st2 + "'where AccountId=" + st,con); dataAdapter.Fill(ds,"contentTable"); } Know what the problem is...there was somany records like (100+ in the database)..if i did like this,it took a database interaction to update each row ...i.e,for the single click it will take 100+ times of database interaction... bcz of performance resion i want to avoid these interactions...i want the updation to be done by making single interaction with the database(i.e i want to handle all the datagrid data and take the updation at single time)......Plz help me out ,,or let me have some articles related to this.... regards yuva
u can use command builder dim da as new sqldatadapter("select * from emp",cn) dim cmb as new sqlcommandbuilder(da) dim dt as new datatable da.fill(dt) dim dr as datarow() dim i as int = 0 while i < grid.items.count -1 dr = dt.select("AccountId=" & s1) if dr.length > 0 then dr(0).item("AccountCode") = s1 dr(1).item("Description") = s2 end if i +=1 end while da.update(dt)