On Mon, Jul 30, 2001 at 12:18:02PM +0100, Christopher Thorpe wrote:
> Hi all quick question
> 
> if I use a query such as the one below
> 
> INSERT INTO usq (usq_id,usq_querystring) VALUES(NULL,'test');
> SELECT LAST_INSERT_ID();
> 
> how do I push this two part query through an ADO command object and how do I
> get the variable back from the select part of the query... alternatively
> should I do it as a recordset update?

Sir, the answer is yes and no. An ADO command object doesn't return 
a value from an SQL statement, so you have to use a recordset object 
to get the return value from the Last_insert_id function. I would do 
the first through a command object, and the second through a 
recordset. It would probably work just as well to use them sequentially 
as the CommandText property of of a command object and execute them 
by opening a recordset. As you are probably aware, there's rarely 
only two ways of doing something with ADO.

I don't think you can use them simultaneously in a single command object. 
But there's no need to; Last_insert-id() returns the last insert id 
for the current connection, regardless of what else has been inserted
in the interim. As long as your connection object stays open, you'll 
get the correct return value.

I would never use rs.Update to do something that can be done 
with an SQL statement. My experience is that recordsets take about 
three to four times as long as SQL when doing single row inserts over 
native connections. 

For code examples, see your friendly neighborhood MS help files. 
I've devoted more than enough space on a MySQL list to ADO. 
-- 
Bob Hall        How to invoke the MySQL list daemon:
                    Sql, table, query and database,
                    Distribute this mail and be quick, potato face!

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to