Question Last_Insert_ID

xRCO

New member
Joined
Dec 21, 2010
Messages
1
Programming Experience
1-3
My table looks like this:
id, name, pass, email
0 , bob , bob , b@b.c
1 , joe , joe , j@e.c
2 , jim , jim , j@m.c
3 , jak , jak , j@k.c

I have a VB.NET program which can connect to a mysql table correctly. On that program I want to have a label, Showing the ID of the LAST person on my table. So with the table above my label will show the number '3' cause that is the most recent id.
However on a table like this:

id, name, pass, email
0 , bob , bob , b@b.c
1 , joe , joe , j@e.c
2 , jim , jim , j@m.c
3 , jak , jak , j@k.c
4 , jon , jon , j@n.c

I want my label to say 4 as a new user registered and the most recent id has risen by one.
How would I be able to get that value from a list of say, 150 accounts.

Any help would be appreciated!
 
I would first ask exactly why you want this value, because it shouldn't really be relevant. Once a user has registered, showing them their own ID might be relevant, but they don't need to know the last person's ID. The two would usually be offset by 1, but not always. Also, for administrators, a count of users would likely be more relevant, rather than the last ID.

That said, if you really want to get the last ID value then you can. I don't use MySQL so I'm not 100% sure of the syntax, but it would likely be similar, if not exactly the same, as SQL Server:
VB.NET:
SELECT MAX(ID) FROM MyTable
You just need to execute that SQL query using ADO.NET.
 
Back
Top