通过使用OLEDB取得在vb.net中的SQL Server打印语句的值 [英] Get the value of print statement of sql server in vb.net by using oledb
问题描述
我想创建一个查询分析器和执行者。
I am trying to create an query analyzer and executor.
我不知道该如何得到这样的打印
I wonder that how to get the output message of an transact-sql statement like 'PRINT'
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
can you please help me to get the value of print statement of above code in vb.net
在此先感谢
推荐答案
从 MSDN :
您可以检索从SQL Server警告和参考消息 使用SqlConnection对象的InfoMessage事件的数据源。
You can retrieve warnings and informational messages from a SQL Server data source using the InfoMessage event of the SqlConnection object.
这是正在这里所指包括值由返回的信息性消息的打印命令。
The informational messages that is being referred here includes the value being returned by print command.
更新:
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是你的字符串构建器。
Where myConnection is you SQL connection and mySB is your String Builder.
e.Message有打印值
。
e.Message has the value of print
.
这篇关于通过使用OLEDB取得在vb.net中的SQL Server打印语句的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!