Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I have two update statements and I have to join them , so that it updates both the tables. please help..


SQL
UPDATE Admin_Branch set BranchName=@BranchName where BranchCode=@BranchCode

UPDATE Admin_Tier set TierName=@TierName where TierCode=@TierCode


There is TierCode common in both table.


Thanks
Posted
Comments
ZurdoDev 10-Apr-13 10:12am    
What's wrong with doing 2 update statements? I'm pretty sure you'll have to use 2 if you want to update 2 separate tables.
babli3 10-Apr-13 10:14am    
But can I have 2 update statements for one gridview control?
When I tried It says i cant have 2 update statements .
Prasad Khandekar 10-Apr-13 11:04am    
No not in gridview.

You can't update two tables at once in SQL. However you could wrap both updates within a begin transaction / commit pair to ensure that they are treated as a "single" update.

You might also consider linking the two updates with an OUTPUT clause http://msdn.microsoft.com/en-gb/library/ms177564(v=sql.90).aspx[^]
 
Share this answer
 
Hello,

You can have multiple statements in the CommandText of a SqlCommand object. If you're doing multiple UPDATEs then you need to execute them inside a transaction so that you can rollback if there is a failure in one of the statements.

Regards,
 
Share this answer
 
Comments
CHill60 10-Apr-13 10:20am    
Apologies for the overlap in posting
babli3 10-Apr-13 10:31am    
Can you please give me a small example as I am very new to this. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900