如何在C#中显示SQL“PRINT”命令的输出?
发布时间:2020-12-15 18:24:46 所属栏目:百科 来源:网络整理
导读:我有一个SQL程序总是返回“PRINT”命令,我想提取这个“PRINT”命令的输出,即C#中的程序我该怎么做?这是程序 ALTER PROC ResultsPoll@pollid INT ASDECLARE @count1 INT DECLARE @count2 INT DECLARE @count3 INT DECLARE @count4 INT DECLARE @count5 INT D
我有一个SQL程序总是返回“PRINT”命令,我想提取这个“PRINT”命令的输出,即C#中的程序我该怎么做?这是程序
ALTER PROC ResultsPoll @pollid INT AS DECLARE @count1 INT DECLARE @count2 INT DECLARE @count3 INT DECLARE @count4 INT DECLARE @count5 INT DECLARE @test VARCHAR(MAX) DECLARE @value VARCHAR(MAX) SELECT @count1 = COUNT(mem_id) FROM Students_answer_Polls INNER JOIN Polls ON Polls.poll_id = Students_answer_Polls.poll_id WHERE Students_answer_Polls.poll_id = @pollid AND Students_answer_Polls.answer = Polls.a1 SELECT @count2 = COUNT(mem_id) FROM Students_answer_Polls INNER JOIN Polls ON Polls.poll_id = Students_answer_Polls.poll_id WHERE Students_answer_Polls.poll_id = @pollid AND Students_answer_Polls.answer = Polls.a2 SELECT @count3 = COUNT(mem_id) FROM Students_answer_Polls INNER JOIN Polls ON Polls.poll_id = Students_answer_Polls.poll_id WHERE Students_answer_Polls.poll_id = @pollid AND Students_answer_Polls.answer = Polls.a3 SELECT @count4 = COUNT(mem_id) FROM Students_answer_Polls INNER JOIN Polls ON Polls.poll_id = Students_answer_Polls.poll_id WHERE Students_answer_Polls.poll_id = @pollid AND Students_answer_Polls.answer = Polls.a4 SELECT @count5 = COUNT(mem_id) FROM Students_answer_Polls INNER JOIN Polls ON Polls.poll_id = Students_answer_Polls.poll_id WHERE Students_answer_Polls.poll_id = @pollid AND Students_answer_Polls.answer = Polls.a5 SELECT @test=Polls.a1 FROM Polls WHERE poll_id = @pollid IF(@test IS NOT NULL) BEGIN PRINT ('Number of students who chose '+@test+' is:'+' '+CAST (@count1 AS VARCHAR(MAX))) END SELECT @test=Polls.a2 FROM Polls WHERE poll_id = @pollid IF(@test IS NOT NULL) BEGIN PRINT ('Number of students who chose '+@test+' is:'+' '+CAST (@count2 AS VARCHAR(MAX))) END SELECT @test=Polls.a3 FROM Polls WHERE poll_id = @pollid IF(@test IS NOT NULL) BEGIN PRINT ('Number of students who chose '+@test+' is:'+' '+CAST (@count3 AS VARCHAR(MAX))) END SELECT @test=Polls.a4 FROM Polls WHERE poll_id = @pollid IF(@test IS NOT NULL) BEGIN PRINT ('Number of students who chose '+@test+' is:'+' '+CAST (@count4 AS VARCHAR(MAX))) END SELECT @test=Polls.a5 FROM Polls WHERE poll_id = @pollid IF(@test IS NOT NULL) BEGIN PRINT ('Number of students who chose '+@test+' is:'+' '+CAST (@count5 AS VARCHAR(MAX))) END 解决方法
您需要订阅
SqlConnection.InfoMessage 活动.
MSDN有一些示例代码here. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |