我正在尝试创建一个查询分析器和执行器。
我想知道如何获取像“PRINT”这样的transact-sql语句的输出消息
declare @msg varchar(100)
set @msg = select [column] from [table name] where [column] = [condition]
if @msg = 'SOMEVALUE'
begin
print 'This is first statement'
end
else
begin
print 'This is second statement'
end
你能帮我获取上面代码在vb.net中打印语句的值吗
提前致谢
最佳答案
来自MSDN :
You can retrieve warnings and informational messages from a SQL Server data source using the InfoMessage event of the SqlConnection object.
此处引用的信息消息包括 print 命令返回的值。
更新:
AddHandler myConnection.InfoMessage, New SqlInfoMessageEventHandler(AddressOf OnInfoMessage)
Private Sub OnInfoMessage(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs)
mySB.AppendLine(e.Message)
End Sub
其中 myConnection 是您的 SQL 连接,mySB 是您的字符串生成器。
e.Message 的值为 print
。
关于sql - vb.net中使用oledb获取sql server print语句的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22995425/