Last post Apr 10, 2012 09:27 AM by tinku1303
Apr 10, 2012 08:14 AM|tinku1303|LINK
Hi i have a grid and down of grid i have some textboxes...when user select some rows from that grid and enter some info in textboxes and click on add..than it has to insert multiple rows in a table with that id(selected in grid)...for ex: i have a grid with
stdtid, stdtname, stdtcontact..
down i have a textboxes coursename, dept and location..if user select some rows(stdtid 1, 2 ,3,4) and enterd info like .Net, IT, India. then it has to insert in course table like this
stdt1, .Net, IT, India
stdt2, .Net, IT, India
stdt3, .Net, IT, India
stdt4, .Net, IT, India...how to do that
Apr 10, 2012 08:26 AM|chandrashekar|LINK
try below links:
Apr 10, 2012 08:31 AM|sriramabi|LINK
try this way
You have to use UNION
ALLs in SQL Server 2005 to insert multiple rows in a SQL script in a single statement.
INSERT INTO Table (Name, Location) SELECT 'Name1', 'Location1' UNION ALLSELECT 'Name2', 'Location2'UNION ALLSELECT 'Name3', 'Location3'
The other main alternative is to repeat the Insert statement
multiple times which is even more verbose. You need to be careful to use Explicit transactions in this last case to avoid the overhead of many individual commits (and for atomicity reasons of course)
If you have lots of rows to insert you could use BULK
INSERT to load it all in from a delimited file in one statement.
Finally if this is data already in the database that you are scripting out (perhaps to deploy on another server) theSSMS
Tools Pack addin has a "Generate Insert Statements" function that can generate these statements for you.
Apr 10, 2012 08:32 AM|ramiramilu|LINK
in your button click, iterate all gridview rows and get the checkbox using FindControl, then check for its IsChecked property...if it is checked temporarily store that value...
Now get Gridview.DataSource as DataTable, with the IDs you know in your previous step, get thos rows and using LINQ or normal iteration update the columns with TextBox Data,...
Finally rebind DataTable to GridView....
Apr 10, 2012 08:36 AM|sriramabi|LINK
Apr 10, 2012 08:47 AM|jancy abraham|LINK
In case of gridview we have to find all the selected checkboxes, ie first find the cheked checkboxes using foreach loop through the grid.If it is checked find the ID of the student in that row and call proceudure or write qry to insert the data for that
Apr 10, 2012 08:50 AM|tinku1303|LINK
Thanks for ur replies..but i want to insert multiple rows with all fields same only one filed diff which thety select from grid..
when they select from grid it will stote in stdtidlike (1,2,3,4)
if i am writing insert stmst like this
insert into course(coursename, dept, loc, stdtid) values (.Net, IT, India, (1,2,3,4))...its storing like this..becoz in stdtid its storing whatever the rows i selected...but i want this operation individually..
Apr 10, 2012 09:00 AM|jancy abraham|LINK
You have to iterate it through for each loop. Then you can find it individually and insert it individually.ie insert statement inside the loop
Apr 10, 2012 09:27 AM|tinku1303|LINK
Thanks i got by using for each loop..