Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 22nd, 2012, 12:29 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile Update multiple rows at once with different values

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 with different values 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.

Please help me, I am stuck on it for many days...
Reply With Quote
  #2 (permalink)  
Old February 23rd, 2012, 04:33 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

Hi there

you can't update a set of records with different conditions at once

update each row:

Update tbl1 set x = 'a' where id=1
Update tbl1 set x = 'b' where id=2
Update tbl1 set x = 'c' where id=3


batch update:
update tbl1 set x = 'y' where date > '2010-10-10'
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #3 (permalink)  
Old February 23rd, 2012, 08:52 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

isn't is possible with case?
Thanks
Reply With Quote
  #4 (permalink)  
Old February 25th, 2012, 06:09 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile YES. case

Here is what you should do instead:

UPDATE categories
     SET display_order = CASE id
          WHEN 1 THEN 3
          WHEN 2 THEN 4
          WHEN 3 THEN 5
     END
WHERE id IN (1,2,3)

see this link:
http://www.catswhocode.com/blog/10-s...-your-database
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #5 (permalink)  
Old February 25th, 2012, 09:24 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi,
I found that link very early that is why I asked about case. But I am stuck on how I pass the multiple records to some function (stored procedure) that are to be updated.
Thanks...
Reply With Quote
  #6 (permalink)  
Old March 1st, 2012, 01:46 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Please anybody give suggestions.

I want to update multiple rows at once not the multiple columns.
Thanks
Reply With Quote
  #7 (permalink)  
Old March 1st, 2012, 01:56 AM
Imar's Avatar
Wrox Author
Points: 66,749, Level: 100
Points: 66,749, Level: 100 Points: 66,749, Level: 100 Points: 66,749, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,143
Thanks: 65
Thanked 1,391 Times in 1,371 Posts
Default

Why not simply execute the stored procedure multiple times? Or use a DataSet and update the values and save them. Or use EF which handles all of this pretty nicely.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #8 (permalink)  
Old March 1st, 2012, 02:53 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Greetings Imar,

Quote:
Why not simply execute the stored procedure multiple times?
if I am not wrong then won't it hit database multiple times?

Quote:
use EF which handles all of this pretty nicely.....
how EF can do this, would it handle multiple rows or multiple columns?

My scenario is:
Table Structure: Id SettingName Value
Now values in table are as follows

1 CommentsAllowed No(0)
2 SentEmailAfterComment Yes(1)
3 CommentsPerPage 10
4 ReviewsPerPage 5
5 ShowNonAuthReviews No(0)

etc....

So if in a web form I want to update first 3 rows and on second web form I want to update last 2 rows, then is it possible with EF?

Please reply
Thanks
Reply With Quote
  #9 (permalink)  
Old March 1st, 2012, 05:52 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

Hi Sophia

EF does not apply changes as done. when you use ef_instance.SubmitChanges() then updated records will be updated in Database. this is because of when you change a property value of some model instance, INotifyPropertyChanging and INotifyPropertyChanged interface implemented class (EF) marks the model to be updated when SubmitChanges is called.
so you can updated multiple rows at once. I thought that you want to do it only by StoredProcedure
__________________
happy every time, happy every where

Reza Baiat
Reply With Quote
  #10 (permalink)  
Old March 1st, 2012, 11:18 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Can you please give some sample code from getting values from server controls (textbox & checkbox etc) from web form to passing these values to stores procedures and save them?

Please help.
Thanks
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple columns in an update statement debbiecoates SQL Server 2000 1 August 17th, 2008 04:01 AM
update rows with vbscript in asp sanjeev jha Classic ASP Professional 1 November 12th, 2007 02:24 AM
Highlighting multiple rows nzhang ASP.NET 2.0 Basics 1 June 21st, 2006 11:12 PM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 06:11 PM
Updating multiple Rows from multiple fields in ASP vdm_nana SQL Server ASP 0 April 1st, 2004 03:26 AM



All times are GMT -4. The time now is 10:04 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.