本文介绍了INSERT操作(SQL / ASP)上的返回键(标识)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有以下SP: CREATE PROCEDURE Orders_CreateOrder @CustomerID int, @LocationID int, @CustOrderNo varchar(20), @OrderDate smalldatetime AS 插入订单(CustomerID) ,LocationID,CustOrderNo,OrderDate) 值(@ CustomerID,@ LocationID,@ CustomerOrderNo,@ OrderDate) 如果@@ RowCount> 0 选择Scope_Identity()作为OrderID GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO 理论上说如果Insert操作成功,那么键是 (Scope_Identity)被返回。 如果我在QA中尝试以下操作,它可以工作:Exec Orders_CreateOrder 1,1, ''123d'', ''20040323'' 但是,在我的ASP代码中,我收到一个错误: 关闭对象时不允许操作。 ; ASP片段: sSQL =" Exec Orders_CreateOrder" &安培; _ Request.Form(" CustomerID")& , &安培; _ Request.Form(" Depot")& ",''" &安培; _ Request.Form(" CustOrderNo")& '',''" &安培; _ ISODate(Request.Form(" OrderDate"))& "''" 设置rsOrders = oConn.Execute(sSQL) 有什么想法吗? 干杯 克里斯 I have the following SP: CREATE PROCEDURE Orders_CreateOrder@CustomerID int,@LocationID int,@CustOrderNo varchar(20),@OrderDate smalldatetimeAS Insert into Orders (CustomerID, LocationID, CustOrderNo, OrderDate)Values (@CustomerID, @LocationID, @CustOrderNo, @OrderDate)If @@RowCount > 0Select Scope_Identity() as OrderIDGO SET QUOTED_IDENTIFIER OFFGOSET ANSI_NULLS ONGO The theory is that if the Insert operation is successful, the key(Scope_Identity) is returned. If I try the following in QA, it works: Exec Orders_CreateOrder 1, 1,''123d'', ''20040323'' However, in my ASP code, I get an error:"Operation is not allowed when the object is closed."ASP Snippet:sSQL = "Exec Orders_CreateOrder " & _Request.Form("CustomerID") & ", " & _Request.Form("Depot") & ", ''" & _Request.Form("CustOrderNo") & "'', ''" & _ISODate(Request.Form("OrderDate")) & "''" Set rsOrders = oConn.Execute(sSQL)Any ideas? Cheers Chris推荐答案 这篇关于INSERT操作(SQL / ASP)上的返回键(标识)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 23:21