Please Help: How to get auto-generated code to return new ID of inserted record?

B

Bobby Edward

I am using VS 2008 SP1, ASP.NET 3.5, VB.NET, MySQL (latest version).

I created a new dataset using VS. In the ds I have a users table. I let it
create the "Fill, GetData" functions in the usersTableAdapter.

When I call the INSERT command, how do I get it to return the ID (the PK) of
the newly created record?

I pulled up the properties of the TableAdapter, then went to the
InsertCommand/Parameters. I added a parameter (for the pk I want) and made
it have a "ReturnValue" Direction.

What am I missing?

In my code I did a "Goto Definition" of the Insert command I called. It
brought me to the VS "auto generated code". I noted that the auto-generated
code does an ExecuteNonQuery. I suspect this needs to change but I don't
know how to! I don't want to edit the code directly since it's
"auto-generated".

Please help!!!
 
B

Bobby Edward

sloan said:
Maybe this can help

http://www.codeproject.com/KB/database/MySqlUtil.aspx

Or maybe do some googling on:
LAST_INSERT_ID
AUTO_INCREMENT

Plus the other keywords you list:

TableAdapter Insert MySql

Thanks Sloan. I've been digging for 2 hours but haven't been able to find a
solution.

Some have suggested checking the "Refresh the data table" checkbox in the
Advanced Options of the Tabledapter Configuration Wizard, but for some
reason this doesn't modify anything as people have suggested. (It's
supposed to add a SELECT statement after the INSERT query. But it doesn't
for me.)

Any more suggestions would be appreciated...

I'm sure that there are alot of people using MySQL with the VS TableAdapter
dataset stuff.

Hopefully they'll come to my rescue!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top