Well to update mutiple rows in SQL you use an update statement and a where clause if the rows have something in common.
update emptab set settingname = 'blah blah', value = 'bla bla' where (condition)
Or if they don't have something in common you'd have to loop through and perform an ado command for every row you wanted to update. You could make a method out of the code sample in the link below, and call it for every row you wanted to update, passing
in a different parameter every time, or depending on what page in your application the save button is clicked
Or if they don't have something in common you'd have to loop through and perform an ado command for every row you wanted to update. You could make a method out of the code sample in the link below, and call it for every row you wanted to update, passing
in a different parameter every time, or depending on what page in your application the save button is clicked
I do not want to loop through rows as it will hit database those many times.
I want to update multiple rows having different values in single update query, and also I want to retrive those multiple
sophia_asp
Member
521 Points
469 Posts
Update multiple rows at once
Jan 11, 2012 07:13 PM|LINK
Hello all,
I have a table named EmpTab. I have few records in it.
I want to update some of those records at once that is when Save buttons is clicked then the
few records must be updated. The whole table (all records are splitted in many web forms) it means
page 1 contains 1-6 records to update, page 2 contains 7-10 records to update.
So how multiple records can be updated by a single page on button's click event.
Table structure is like this
Id SettingName Value
SettingName contains the setting name, and value contains the actual value.
attrib75
Member
367 Points
218 Posts
Re: Update multiple rows at once
Jan 11, 2012 09:12 PM|LINK
Well to update mutiple rows in SQL you use an update statement and a where clause if the rows have something in common.
update emptab set settingname = 'blah blah', value = 'bla bla' where (condition)
Or if they don't have something in common you'd have to loop through and perform an ado command for every row you wanted to update. You could make a method out of the code sample in the link below, and call it for every row you wanted to update, passing in a different parameter every time, or depending on what page in your application the save button is clicked
http://www.csharp-station.com/Tutorial/AdoDotNet/Lesson02
sophia_asp
Member
521 Points
469 Posts
Re: Update multiple rows at once
Jan 12, 2012 06:51 PM|LINK
I do not want to loop through rows as it will hit database those many times.
I want to update multiple rows having different values in single update query, and also I want to retrive those multiple
records on their respective pages on Page Load.
Many thanks,,,
rajanireddy
Member
362 Points
161 Posts
Re: Update multiple rows at once
Jan 13, 2012 08:49 AM|LINK
Ok, the best oiption is try with XML.
It can be done very easily.
ssjGanesh
Participant
1928 Points
1352 Posts
Re: Update multiple rows at once
Jan 13, 2012 09:01 AM|LINK
IF 1-6 RECORDS comes from page 1 means how u stored that in table,do u maintain any Id for identify these records comes from this page?
If it so update by using that id.
If it not so u should maintain a common Id for all pages. U have to store that Id when u store records in ur table.
For example,
Table1
--------
Id name value pageId
----------------------------
1 a a 1
2 b b 1
3 c c 2
4 d d 2
U shold have this type of table then only u have update or delete group of records at once.
EX: Update Table1 set value="somethng" where pageId=2
The above query can update multiple records at a single execution..
Mark as answer,if it helped U!
DotNetSeeker
Contributor
3169 Points
589 Posts
Re: Update multiple rows at once
Jan 13, 2012 01:44 PM|LINK
Here's an example
http://simpledotnetsolutions.wordpress.com/2011/10/22/listview-bulk-edit-using-ado-nets-batchupdate-and-jquery/
2011 Microsoft Community Contributor Award Recipient
sophia_asp
Member
521 Points
469 Posts
Re: Update multiple rows at once
Jan 13, 2012 05:06 PM|LINK
Hi Ganesh, won't it update all values to same value on a specific page! I do not want this...
Hi Dotnetseeker,
article uses for loop and also it is updating multiple fields not the multiple records, that I do not want...
Thanks for your replies.....
rajanireddy
Member
362 Points
161 Posts
Re: Update multiple rows at once
Jan 16, 2012 03:41 AM|LINK
You dont want to use for loop or you dont want multiple database hits?
sophia_asp
Member
521 Points
469 Posts
Re: Update multiple rows at once
Jan 16, 2012 08:00 AM|LINK
Exactly, I do not want for loop and hence multiple hits to database...
tarunSaini
Contributor
2948 Points
985 Posts
Re: Update multiple rows at once
Jan 16, 2012 08:05 AM|LINK
depend on your key value .