Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how do update two table in single query using vb.net
Posted

Assuming that the two tables are related, you could use a JOIN - but if you mean that you want to INSERT rows to two related tables, then you would probably be better off creating a Stored Procedure to do two inserts within a single Transaction - so if the second fails, it doesn't leave your DB in a confused state.
 
Share this answer
 
you can use store procedures

you can refer this code project articles

Overview-of-SQL-Server-Stored-Procedure
 
Share this answer
 
The following query meets your requirement

SQL
UPDATE t1
  SET t1.Column1 = t2.Column2, t2.Column3 = t1.Column4
  FROM Table1 AS t1
  INNER JOIN Table2 AS t2
  ON t1.CommonField = t2.[Common Field]
  WHERE t1.BatchNo = '110';


You can use the above query in vb.net and update the two tables with a single query.
Hope this helps.
 
Share this answer
 

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