Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MySQL - AUTO INCREMENT

Posted on 2002-05-01
10
Medium Priority
?
559 Views
Last Modified: 2010-04-04
After I insert a row by SQL statement, a auto increment value will be assigned. How can I retrive this auto increment value ?

Andrew
0
Comment
Question by:andrewyu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6985285
hi,
 you may be able to use mysql_insert_id :
http://www.mysql.com/doc/m/y/mysql_insert_id.html

also maybe of interest:
http://www.mysql.com/doc/e/x/example-AUTO_INCREMENT.html

else i guess a stored procedure ,i dunno about using them but someone (like meikl :) be along soon enough..
0
 
LVL 17

Expert Comment

by:inthe
ID: 6985302
sorry i was thinking php ,i meant use a select statement with LAST_INSERT_ID()instead.

http://www.mysql.com/doc/O/D/ODBC_and_last_insert_id.html
http://www.mysql.com/doc/G/e/Getting_unique_ID.html
0
 

Author Comment

by:andrewyu
ID: 6985308
I tried LAST_INSERT_ID, but, raise a DBException.

Andrew
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthe
ID: 6985317
how are you connecting to mysql
0
 
LVL 17

Expert Comment

by:inthe
ID: 6985421
hi,
i tested an example ,it works fine here :

procedure TForm1.Table1AfterPost(DataSet: TDataSet);
var
 i:  integer;
begin
 Query1.sql.add('insert into testtable(name)');
 Query1.sql.add(' values(''barry'')');
 Query1.execSql;
 Query1.close;
 Query1.sql.clear;
 Query1.sql.add('SELECT LAST_INSERT_ID()');
 Query1.open;
 Query1.first;
 i := Query1.fields[0].asInteger;
 form1.caption := inttostr(i);
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 6985425
ps,
you can delete the first three lines
(i tested on a button first :)
0
 

Author Comment

by:andrewyu
ID: 6985968
I had already tried it and it raised a exception.

I use dbExpress to establish connection with mysqld-max-nt.

Andrew
PS:they are running on same Windows XP Professional machine
0
 
LVL 17

Expert Comment

by:inthe
ID: 6988070
hi andrew,
sorry i dont have dbExpress to try it out.
someone else may have idea ,i guess not many people here are using mysql,normally db questions have lots of commenters..
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004484
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9096610
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question