运行 SQL 存储过程并返回打印消息 vb.net [英] Run SQL Stored Procedure And Return Print Message vb.net
本文介绍了运行 SQL 存储过程并返回打印消息 vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 2 个参数的存储过程,它返回的结果是一个 PRINT
消息.我可以传入参数并运行存储过程,但我不知道如何返回结果.
I have a stored procedure with 2 parameters and which returns result is a PRINT
message. I can pass the parameters in and run the stored procedure but I can't figure out how to return the result.
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Dim SQL As New SQLControl
Dim cmd As New SqlCommand
Private Sub RunSql_Click(sender As System.Object, e As System.EventArgs) Handles RunSql.Click
Try
If SQL.HasConnection = True Then
SQL.SQLCon.Open()
cmd.Connection = SQL.SQLCon
cmd.CommandText = "Exec stored procedure " & param1.Text & "," & param2.Text
cmd.ExecuteNonQuery()
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
SQL.SQLCon.Close()
End Try
End Sub
End Class
提前致谢.
推荐答案
您可以从 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.
这已经在一个类似的问题中得到了回答:获取使用oledb在vb.net中sql server的print语句的值
This has been answered in a similar question: Get the value of print statement of sql server in vb.net by using oledb
这篇关于运行 SQL 存储过程并返回打印消息 vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文