如何从后面的代码中的插入存储过程中获取返回值 [英] How to get return value from an insert stored procedure in code behind

查看:73
本文介绍了如何从后面的代码中的插入存储过程中获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我在数据库中将新插入的项目的新ID返回到C#代码时遇到问题(我需要它来以表单形式显示新项目)...我的存储过程已设置,因此它返回scope_identity(尝试使用select并输出).但是,当我运行

Hi!

I have a problem with returning the new id of the newly inserted item in database back to C# code(i need it for displaying the new item in the form)... My stored procedure is setup, so it returns scope_identity(tried with select and output as well). But when I run

int newID = customerTableAdapter.Insert(values...)

时,新的id设置为-1,在tableAdapter参数集合中是否需要配置一些属性(我尝试将collumnName和sourceCollumn设置为CustomerID,但是似乎没有任何作用)将返回新的标识,因为在SQL Management Studio中运行时SP返回新的ID?

提前谢谢...

B

new id is set to -1, are there some properties that need to be configured in the tableAdapter parameters collection(I tried setting the collumnName and sourceCollumn to CustomerID but nothing seems to work), so that the fuction will return the new identity, becouse the SP when run in SQL Management Studio returns the new id?

Thanks in advance...

B

推荐答案

看看这个博客.它有一个非常完整的示例,该示例从存储过程返回值: http://blogs.msdn.com/b/smartclientdata/archive/2006/08/09/693113.aspx [
Have a look at this blog. It has a very thorough example of returning a value from a stored procedure: http://blogs.msdn.com/b/smartclientdata/archive/2006/08/09/693113.aspx[^]


这篇关于如何从后面的代码中的插入存储过程中获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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