Click to See Complete Forum and Search --> : Get Index After INSERT Query


megetron
May 3rd, 2004, 09:04 AM
Hi,
I am using ASP, and write a query that insert a record, using the recordset object:

rs.open strSQL, adoCon, 3, 3

the query is creating a uniqe ID automatically.
I wants this ID after the query, and i was thinking using the
rs.index property.
but it isn't working, for some reason the recordset is get closed imiddietly after the INSERT query is performed.
any suggestions?

hspc
May 7th, 2004, 08:52 AM
1-open the table :
rs.Open "Select ID,field1,Field2 ,... from MyTable",adoCon, 2, 3

2-Add the new record:
rs.AddNew.....

3-rs.Update

4-NewIndex=rs.("ID")

5-rs.close

megetron
May 9th, 2004, 03:44 AM
I dont need "select" query.
here is my code:

strSQL = "INSERT INTO store (col1,col2 ) VALUES ('a','b')"
rs.open strSQL, adoCon, 2, 3

how should I use the addNew code here?
do I really need it in this case?

hspc
May 9th, 2004, 05:23 AM
the way I sent just works :)

no other way if you use access.

if you use SQL server you can write a stored procedure that returns the last number.

megetron
May 9th, 2004, 06:32 AM
i had to move back and forward, and the id was updated:
rsStore.moveprevious
rsStore.movenext
newIndex=rsStore("ID")


10x alot