SQL SELECT INSERTed 表中的数据
它是 ASP Classic 中的。 MS-Access 数据库。
我这样做: INSERT INTO Orders (userId) VALUES (123)"
我想要检索的是该行中的 orderNumber
。它是一个自动递增的数字。
所以我这样做了: SELECT orderNumber FROM Orders WHERE userId=123
但由于位于同一页面,因此 SELECT 返回:BOF 或 EOF 为 True,或者当前记录已被删除 请求的操作需要执行。当前记录。
我在某处看到将 orderNumber 作为变量
但它是针对 Oracle 的,我不知道如何将其实现到我的 asp 中:(
set addOrder = Server.CreateObject("ADODB.Command")
addOrder.ActiveConnection = MM_KerenDB_STRING
addOrder.CommandText = "INSERT INTO Orders (userId) VALUES ("&userId&")"
addOrder.CommandType = 1
addOrder.CommandTimeout = 0
addOrder.Prepared = true
addOrder.Execute()
Dim getOrderNumber
Set getOrderNumber = Server.CreateObject("ADODB.Recordset")
getOrderNumber.ActiveConnection = MM_KerenDB_STRING
getOrderNumber.Source = "SELECT orderNumber FROM Orders WHERE userId=" & userId
getOrderNumber.CursorType = 0
getOrderNumber.CursorLocation = 2
getOrderNumber.LockType = 1
getOrderNumber.Open()
session("orderNumber") = getOrderNumber.Fields.Item("orderNumber").value
its in ASP Classic. MS-Access DB.
i do: INSERT INTO Orders (userId) VALUES (123)"
what i want to retrieve is orderNumber
from that row. its an auto-increment number.
so i did: SELECT orderNumber FROM Orders WHERE userId=123
but since it is on the same page, the SELECT returns: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
i've seen somewhere RETURNING orderNumber as variable
but it was for oracle and i dont know how to implement it into my asp :(
set addOrder = Server.CreateObject("ADODB.Command")
addOrder.ActiveConnection = MM_KerenDB_STRING
addOrder.CommandText = "INSERT INTO Orders (userId) VALUES ("&userId&")"
addOrder.CommandType = 1
addOrder.CommandTimeout = 0
addOrder.Prepared = true
addOrder.Execute()
Dim getOrderNumber
Set getOrderNumber = Server.CreateObject("ADODB.Recordset")
getOrderNumber.ActiveConnection = MM_KerenDB_STRING
getOrderNumber.Source = "SELECT orderNumber FROM Orders WHERE userId=" & userId
getOrderNumber.CursorType = 0
getOrderNumber.CursorLocation = 2
getOrderNumber.LockType = 1
getOrderNumber.Open()
session("orderNumber") = getOrderNumber.Fields.Item("orderNumber").value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用他们使用 ADO 对象添加记录的方法,以下内容可能会有所帮助。
http://support.microsoft.com/kb/221931
但没有真正看到你经典 ASP代码,很难给你正确的答案。
The following might be of help if you are using their method of adding records using ADO objects.
http://support.microsoft.com/kb/221931
But without actually seeing you Classic ASP code, it is hard to give you a proper answer.