Fw: getting ID back after an insert statement

Fw: getting ID back after an insert statement

am 22.08.2005 16:33:27 von tony yau

mysql_insert_id(connMySQL).

does it re-query the database?

----- Original Message -----

> From: "Mark Mchugh"
> To: "mysql list"
> Sent: Monday, August 22, 2005 3:21 PM
> Subject: getting ID back after an insert statement
>
>
> > hi,
> > I am using the following code
> >
> > Set rs = New ADODB.Recordset
> > rs.ActiveConnection = connMySQL
> > rs.Open sqlstr
> > sqlstr = "insert into
> > contacts(classification,companyname,fname, lname,
> > addr1,
> > addr2,addr3,town,county,position,landline,fax,email,mobile)
> > values ( " & "'" & ctype & " ','" & Text13.Text &
> > "','" & Text1.Text & "','" & Text2.Text & "', '" &
> > Text3.Text & "','" & Text4.Text & "', '" & Text5.Text
> > & "','" & Text6.Text & "','" & Text7.Text & "','" &
> > Text9.Text & "','" & Text10.Text & "','" & Text11.Text
> > & "','" & Text12.Text & "','" & Text13.Text & "');"
> >
> >
> > this table has an ID field which is auto-incremented.
> > is there a way to get the ID of the item added from
> > the above SQL without having to re-query the database?
> >
> >
> >
> > thanks
> >
> > MArk
> >
> >
> >
> > ____________________________________________________
> > Start your day with Yahoo! - make it your home page
> > http://www.yahoo.com/r/hs
> >
> >
> > --
> > MySQL Windows Mailing List
> > For list archives: http://lists.mysql.com/win32
> > To unsubscribe:
> http://lists.mysql.com/win32?unsub=tony.yau@emigen.co.uk
> >
> >
>


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: Fw: getting ID back after an insert statement

am 22.08.2005 17:53:23 von Daniel da Veiga

Check the list of methods for the connection object, there is one to
get the last AI value inserted with the connection.

--=20
Daniel da Veiga
Computer Operator - RS - Brazil
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V-
PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++
------END GEEK CODE BLOCK------

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

Re: Fw: getting ID back after an insert statement

am 22.08.2005 18:22:21 von Matt Bernhardt

I believe the statement is:

SELECT LAST_INSERT_ID();

http://dev.mysql.com/doc/mysql/en/information-functions.html

Hope this helps...
Matt
bernhardt.7@osu.edu

On Mon, 22 Aug 2005 12:53:23 -0300, Daniel da Veiga
wrote:

> Check the list of methods for the connection object, there is one to
> get the last AI value inserted with the connection.
>



--
Matt Bernhardt, bernhardt.7@osu.edu
Systems Analyst - Student Computing
Knowlton School of Architecture
The Ohio State University

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: Fw: getting ID back after an insert statement

am 22.08.2005 19:57:26 von Daniel da Veiga

On 8/22/05, Matt Bernhardt wrote:
> I believe the statement is:
>=20
> SELECT LAST_INSERT_ID();
>=20
> http://dev.mysql.com/doc/mysql/en/information-functions.html

Yeah, its a solution, but that would query the database again, the
connection object should hold information about the last Auto
Increment field used and its value, at least the mysql .dll I use to
program vb (vbmysqldirect) has it, so, assuming ADO has way more
resources, it must have one too.

--=20
Daniel da Veiga
Computer Operator - RS - Brazil
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V-
PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++
------END GEEK CODE BLOCK------

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org