C# - 使用 TableAdapter 从存储过程返回单个值返回 null
我不明白,但我添加到表适配器的存储过程仅返回空值。它应该返回一个简单的整数值。在我使用数据集设计器进行的预览中,我可以清楚地获得我想要的整数值。但由于某种原因,我无法从我的代码中获取价值。
我按照MSDN库的说明进行操作: 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 代码是:
DECLARE @r int
SET @r = 7
RETURN @r
谁能让我知道如何解决这个问题? 任何帮助将不胜感激!
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.
I followed the instruction of MSDN library:
http://msdn.microsoft.com/en-us/library/37hwc7kt(VS.80).aspx
My code for c# is:
humansDataSetTableAdapters.ProfilesTableAdapter tableAdapter
= new humansDataSetTableAdapters.ProfilesTableAdapter();
int returnValue = (int)tableAdapter.getSample();
Console.Write(returnValue);
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Scalar 期望的是结果,而不是返回。根据定义,它查找第一列、第一行。
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
Try
如果存储过程返回单个值,我建议您使用 ExecuteScalar,而不是采用此解决方案。
http://msdn.microsoft.com/en -us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
rather than going for this solution I would like to suggest you to use
ExecuteScalar
if stored procedure returning single value.http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
您使用的是类型化数据集吗?如果是这样,请确保您的存储过程设置为返回标量值。
Are you using a typed DataSet? If so, make sure your Stored Procedure is set to return a Scalar value.