More information about the Underscore mailing list

[_] .net tableadapters and MySQL LAST_INSERT_ID command

Jon Free jon at tangymedia.co.uk
Mon May 19 21:23:37 BST 2008

I've done the same thing recently using @@IDENTITY in MySQL and the basic
MySQLCOMMAND object which is part of the MySQL connector dll without any
issue. It would be my guess that your doing some wrong with the adapter and
not the SQL. 

Surely if you run the code by hand you could confirm it was returning the
right result?

-----Original Message-----
From: Jason Nevin [mailto:jason_nevin at yahoo.co.uk] 
Sent: 19 May 2008 18:12
To: underscore at under-score.org.uk
Subject: [_] .net tableadapters and MySQL LAST_INSERT_ID command

I'm using tableadapters to insert a row into a MySQL database. I want to get
the primary key of the inserted row returned. Normally I'd tag a SELECT
SCOPE_IDENTITY() statement onto the end of my insert and make the command a
scalar but when I use the equivalent MySQL command (SELECT LAST_INSERT_ID())
I get a syntax error. Does anybody have a working example?
Here is my SQL statement;
INSERT INTO tblaccess
                      (siteid, floor, room, area, reason,
accessed, accessdate, comment)
VALUES     (?, ?, ?, ?, ?, ?, ?, ?);
SELECT LAST_INSERT_ID() AS ID;
And I get error "Unable to parse query text"
Thanks. 

-- 
underscore_ list info/archive ->
http://www.under-score.org.uk/mailman/listinfo/underscore


-- 
No virus found in this incoming message.
Checked by AVG. 
Version: 7.5.524 / Virus Database: 269.23.20/1453 - Release Date: 18/05/2008
09:31