473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

adodb, sql server, and last insert id

I'm not very familiar with sql server or adodb. I'm writing a python
script that uses adodb as described at http://www.ecp.cc/pyado.html,
but I can't figure out how to get the id of my last insert.

Jul 19 '05 #1
2 3550
jdonnell wrote:
I'm not very familiar with sql server or adodb. I'm writing a python
script that uses adodb as described at http://www.ecp.cc/pyado.html,
but I can't figure out how to get the id of my last insert.

The classic method, IIRC, is as follows for SQL Server and recent
versions of Jet:

curs.execute("SELECT @@IDENTITY")
id = curs.fetchall()[0][0]

For MySQL it would be

curs.execute("SELECT LAST_INSERT_ID()")
id = curs.fetchall()[0][0]

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #2
Thanks for the reply. I found that before I posted, but that doesn't
look thread safe and I haven't found anything that says it is or isn't.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joe | last post by:
I want to add a new record to database, and then retrives the @@IDENTITY value for this ne added record, and the fields of this record. However, it has the following error on line varNewID =...
7
by: Aleks Kleyn | last post by:
At this time my code use ODBC and adodb to access database. Working with win vista i discovered that way i cannot work with SQL server. it is not clear this is bug or Microsoft suppose to give...
4
by: T | last post by:
-------------------------------------------------------------------------------- I tried this audit trail code, using 2003 and it works great, I try and use it at work w/97 and it blows up:...
2
by: ramia1983 | last post by:
All i am doing is trying to write info to a access database but iget this error Error Type: ADODB.Recordset (0x800A0BCD) Either BOF or EOF is True, or the current record has been deleted....
10
by: chuckzter | last post by:
Hey guys, I would like to know how to replace values in your database via ADODB. Example: (I would want to replace the value LOCATION of ID 1001 which is Oliver to Laguna.) ID NAME...
5
by: Jahren | last post by:
Hi! i'm new here. this place looks nice so i would like to try my luck here! I've a question : How can I insert multiline richtext into MSACCESS database? at first I thought I could store it...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
2
bmallett
by: bmallett | last post by:
I am getting the following error: Error Type: ADODB.Command (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another....
2
by: Jerry Winston | last post by:
We all know SQL injection attacks can easily get break SQL command strings concatenated with unsanitized user input fields: set commandObj = Server.CreateObject("ADODB.Connection") set rs =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.