需要获取SQL Server的“ PRINT” C#中的值 [英] Need to get the SQL Server "PRINT" value in C#

查看:146
本文介绍了需要获取SQL Server的“ PRINT” C#中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SP ,可以将结果打印到 SQL Server 中,但是我需要在 C#中使用该值。

I have a SP that Prints the results into SQL Server, but I need to use that value in C#.

PRINT 更改为 SELECT 暂时不是一种选择。我尝试 SqlCommand.ExecuteScalar(),但这没用。

Changing the PRINT to SELECT is not an option right now. I tried to SqlCommand.ExecuteScalar() but that didn't work.

有人知道是否有可能在 SP 中获得 PRINT 命令的值>重定向到 C#

Does anybody know if it is possible to get the value of PRINT command in SP redirected to C#?

示例:

CREATE PROCEDURE doXYZ
AS
BEGIN
   PRINT 'XYZ'
END

现在在 C#中,我需要获取值 XYZ...。有什么想法吗?

Now in C# I need to get the value 'XYZ'.... any ideas?

推荐答案

您可以使用 SqlConnection.InfoMessage 事件。

You can use the SqlConnection.InfoMessage event.

这篇关于需要获取SQL Server的“ PRINT” C#中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆