Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to update multiple table at the same time in c#??
i want to update 4 tables data at a time where one field is comman in all tables..??
how i can..???
Posted

Are you updating database tbales, HTML tables...?

If you are inquiring about database tables, as in you need to update several tables in one go, then have a look at ADO.NET transactions..

Using Transactions in ADO.NET[^]
 
Share this answer
 
Comments
soniya sangal 16-Nov-11 6:36am    
thanx for reply...

ya database tables how i can???
Mel Padden 16-Nov-11 7:12am    
So you need to update the same column in several tables. With the same value?

Create a database transaction, and in the transaction you update each table with the required value. That way, if one fails, you can roll back all the changes.

Something like:

BEGIN TRANSACTION

UPDATE [TableName] Set Col = @Value WHERE <condition>
UPDATE [TableName2] Set Col = @Value WHERE <condition>
UPDATE [TableName3] Set Col = @Value WHERE <condition>

IF @@ERROR <> 0 BEGIN
ROLLBACK
END ELSE BEGIN
COMMIT
END
RaviRanjanKr 16-Nov-11 16:58pm    
My 5+
hi,
in this case u can do following two things..
1. u can use or make StoredProcedure and write your sql statement to insert the data to multiple table at a single time.

and the second way according to me, u can create trigger on perticular table for insert.

visit for more info

http://www.upsizing.co.uk/Art18_CascadeTriggers.aspx[]

hope this help..
 
Share this answer
 
Comments
RaviRanjanKr 16-Nov-11 16:58pm    
My 5+
hi soniya,

you can update multiple tables with a stored procedure also.
Just follow the below link ,i hope it helps you.

Updating Multiple Tables[^]

If you have any query for me, just make a comment or question.
 
Share this answer
 
Comments
RaviRanjanKr 16-Nov-11 16:58pm    
My 5+

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