views:

50

answers:

1

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
+1  A: 

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.

Waleed Al-Balooshi
for some strange reason my code looks completly different from the you pointed in the link.. :/ i feel dumb.. thats what maccromedia gave me.. can i do better? :)
Noam Smadja
@Noam There are multiple ways to work with data in Classic ASP. You can either use ADODB.Command objects to insert/delete/update/select records or you can do the same with ADODB.RecordSet objects. Macromedia seems to use commands for inserting and recordsets for selecting. Note that when you use commands to select you are still getting recordsets back.
Waleed Al-Balooshi
@Waleed i did what was in your link and it worked :) since i always hated macromedia doing it for me, i think its time i really get more into understanding what that code actually does. can u point me where i can read about it? and the differences between command and recordset..
Noam Smadja
@Noam w3schools.com has some nice stuff on ADO in addition to pages on each of the ADO objects and all the properties and methods that they contain. http://www.w3schools.com/ado/default.asp
Waleed Al-Balooshi