问题描述
我不明白,但我添加到表适配器的存储过程只返回空值.它应该返回一个简单的整数值.在我使用数据集设计器的预览中,我可以清楚地获得我想要的整数值.但由于某种原因,我无法从我的代码中获取价值.
I do not understand but my stored procedure which I added to table adapter only returns null value. It is supposed to return a simple integer value. In the preview I had with data set desinger, I could clearly get the integer value that I wanted. But for some reason I cannot get the value from my codes.
我按照 MSDN 库的说明进行操作:http://msdn.microsoft.com/en-us/library/37hwc7kt(VS.80).aspx
I followed the instruction of MSDN library:http://msdn.microsoft.com/en-us/library/37hwc7kt(VS.80).aspx
我的 C# 代码是:
humansDataSetTableAdapters.ProfilesTableAdapter tableAdapter
= new humansDataSetTableAdapters.ProfilesTableAdapter();
int returnValue = (int)tableAdapter.getSample();
Console.Write(returnValue);
我的存储过程 getSample 代码是:
My code for stored procedure getSample is:
DECLARE @r int
SET @r = 7
RETURN @r
谁能告诉我如何解决这个问题?任何帮助将不胜感激!
Can anybody let me know how I can solve this problem??Any help will be appreciated!
推荐答案
标量期望结果,而不是返回.作为定义,它查找第一列,第一行.http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
Scalar expects a result, not a return. Be definition, it looks for the first column, first row.http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
试试
DECLARE @r int
SET @r = 7
SELECT @r
这篇关于C# - 使用 TableAdapter 从存储过程返回单个值返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!