Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Inserting record with Microsoft Access

Reply
Thread Tools

Re: Inserting record with Microsoft Access

 
 
Steve Holden
Guest
Posts: n/a
 
      02-09-2006
Albert Leibbrandt wrote:
>
> jeffhg582003 wrote:
>
>
>>Hi,
>>
>>I am developing a python script which add records to
>>a microsoft access tables. All my tables have autogenerated number
>>fields. I am trying to capture the number generated from the insert but
>>I am not exactly sure how to do that after an insert.
>>

> I had to do something similiar in sql server and the experts back then
> told me that the only way is to write a stored procedure. aparently sql
> server does not have sequences and I am guessing that access is the same.
>

Well the experts were wrong, I suspect. Try

SELECT @@IDENTITY

to return the autonumber key created by the most recent INSERT.

I believe this works for both SQL Server and Access (doesn't anyone use
Google any more?).

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

 
Reply With Quote
 
 
 
 
Frank Millman
Guest
Posts: n/a
 
      02-11-2006

Steve Holden wrote:
> Albert Leibbrandt wrote:
> >
> > jeffhg582003 wrote:
> >
> >
> >>Hi,
> >>
> >>I am developing a python script which add records to
> >>a microsoft access tables. All my tables have autogenerated number
> >>fields. I am trying to capture the number generated from the insert but
> >>I am not exactly sure how to do that after an insert.
> >>

> > I had to do something similiar in sql server and the experts back then
> > told me that the only way is to write a stored procedure. aparently sql
> > server does not have sequences and I am guessing that access is the same.
> >

> Well the experts were wrong, I suspect. Try
>
> SELECT @@IDENTITY
>
> to return the autonumber key created by the most recent INSERT.
>
> I believe this works for both SQL Server and Access (doesn't anyone use
> Google any more?).
>
> regards
> Steve
>


I use SELECT IDENT_CURRENT('tablename').

SELECT @@IDENTITY returns the most recent of all inserts. If you have a
complex transaction which triggers inserts into other tables, it may
not return the one you want.

This one allows you to specify the tablename, and it will return the
most recent key inserted into that table.

I got this from the built-in help for SQLServer. I cannot say whether
it works for Access as well.

Frank

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      02-12-2006
>>>>> "Frank" == Frank Millman <> writes:

Frank> SELECT @@IDENTITY returns the most recent of all
Frank> inserts. If you have a complex transaction which triggers
Frank> inserts into other tables, it may not return the one you
Frank> want.

Frank> This one allows you to specify the tablename, and it will
Frank> return the most recent key inserted into that table.

Frank> I got this from the built-in help for SQLServer. I cannot
Frank> say whether it works for Access as well.

Frank> Frank

I've used SELECT @@IDENTITY to good effect, but I agree that there is
no telling what the scope of the variable holding @@IDENTITY is, and
it could turn out to be a kick in the naughty bits.

Depending on the criteria, you might effect the INSERT for a parent
record, and contiue any child record INSERTs by means of the DLookup()
function (Access-only syntactic sugar around nested SELECTs) without
ever having to know the key you would have discovered through
SELECT @@IDENTITY.

R,
Chris
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
Inserting record with Microsoft Access jeffhg582003 Python 3 02-11-2006 06:29 AM
Re: Inserting record with Microsoft Access Albert Leibbrandt Python 1 02-09-2006 05:39 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57