如何在vb.net中的一个连接中执行2 sql命令 [英] how to execute 2 sql command in one connection in vb.net
本文介绍了如何在vb.net中的一个连接中执行2 sql命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vb.net中的一个连接中执行2 sql命令
解决方案
简单:创建两个单独的SqlCommand对象并将它们连接到同一个SqlCommand对象(如果您不使用SqlDataReaders它会没问题,或者将它们作为单个SqlCommand发送,但用分号分隔两个命令:
Dim cmd 作为 SqlCommand = 新 SqlCommand( INSERT INTO MyTable(MyColumn)VALUES('Hello'); SELECT * FROM MyTable,con)
how to execute 2 sql command in one connection in vb.net
解决方案
Simple: either create two separate SqlCommand objects and connect them to the same SqlCommand object (provided you don't use SqlDataReaders it'll be fine) or send them both as a single SqlCommand but separating the two commands with a semicolon:
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO MyTable (MyColumn) VALUES ('Hello'); SELECT * FROM MyTable", con)
这篇关于如何在vb.net中的一个连接中执行2 sql命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文