ASP.NET TableAdapter的插入不返回正确的标识值 [英] ASP.NET tableadapter insert not returning the correct identity value

查看:104
本文介绍了ASP.NET TableAdapter的插入不返回正确的标识值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Visual &工作室NBSP; 2008年ASP.NET网页codebehind,我打电话在SQL的TableAdapter的加载程序,如下:

In my Visual Studio 2008 ASP.NET web page codebehind, I am calling an add routine in an SQL tableadapter, as follows.

NewLabID = LabItem.AddLaborItem(ThisWONum, TechID, DateTime.Now, DateTime.Now, "Working", "");

记录正在被正确添加,但每一次,而不是实际的新LabID(LabID被定义为int /身份)NewLabID的回报1。自动生成的code将命令

The record is being added correctly, but 'NewLabID' returns 1 every time, not the actual new LabID (LabID is defined as int/identity). The autogenerated code insert command is

INSERT INTO [LaborDetail] ([WONum], [TechID], [StartDate], [StopDate], [OtherType], [OtherDesc])
VALUES (@WONum, @TechID, @StartDate, @StopDate, @OtherType, @OtherDesc);
SELECT LabID FROM LaborDetail WHERE (LabID = SCOPE_IDENTITY())

和自动生成的code调用该是:

and the autogenerated code which calls this is:

returnValue = command.ExecuteNonQuery();

通过这个与调试器步进,的returnValue始终为1。不宜上面的命令返回新标识字段值?

Stepping through this with the debugger, returnValue is always 1. Shouldn't the above command return the new identity field value?

推荐答案

的ExecuteNonQuery返回受影响的行数。您将要使用的ExecuteScalar()代替。

ExecuteNonQuery returns the number of rows affected. You will want to use ExecuteScalar() instead.

这篇关于ASP.NET TableAdapter的插入不返回正确的标识值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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