如何使用vb.net在单个查询中更新两个表 [英] how do update two table in single query using vb.net
本文介绍了如何使用vb.net在单个查询中更新两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用vb.net在单个查询中更新两个表
解决方案
假设这两个表是相关的,你可以使用JOIN - 但如果你的意思是如果要将行插入到两个相关的表中,那么最好创建一个存储过程以在单个事务中执行两次插入 - 因此如果第二个失败,则不会使数据库处于混乱状态。 / blockquote>
你可以使用商店程序
你可以参考这个代码项目文章
SQL-Server-Stored-Procedure概述
以下查询符合您的要求
UPDATE t1
SET t1.Column1 = t2.Column2,t2.Column3 = t1.Column4
FROM 跨度>表1 AS t1
INNER JOIN Table2 AS t2
ON t1.CommonField = t2。[Common Field]
WHERE t1.BatchNo = ' 110';
您可以在vb.net中使用上述查询,并使用单个查询更新这两个表。
希望这有帮助。
how do update two table in single query using vb.net
解决方案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.
you can use store procedures
you can refer this code project articles
Overview-of-SQL-Server-Stored-Procedure
The following query meets your requirement
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.
这篇关于如何使用vb.net在单个查询中更新两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文