Question about Adding

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Question about Adding - RESOLVED

When I add a new record, I've set the ID field to be hidden as this may not be the actual value that is given from the AutoIncrement of the SQL Server.

However, I want the user to know which ID was given.
When my Submit Changes to DB is successful, a messagebox appears telling the user it was successfully updated to the back end.

How can I put it so that the messagebox also displays the correct ID field?

I tried something like;
MessageBox.Show("Update Successful! Filed As ID No. " & .........

That's as far as I got! I thought I could use something like ds1.tables.table1.currentrow.id.value

Any help much appriciated!

Regards,
Luke
 
Last edited:
You can use an output parameter, or you can use a SELECT statement that returns @@IDENTITY, IDENT_CURRENT or SCOPE_IDENTITY. You can read up on these variables at MSDN to decide which is best for your situation.
 
Thanks.

I've just looked at the code that the SQL Data Adapter creates and for the Insert Command I have the following:

SQL InsertCommand1.CommandText = "INSERT INTO table1(ID, Field1, Field2) VALUES (@ID, @Field1, @Field2); SELECT ID, Field1, Field2 FROM table1 WHERE ID=@@IDENTITY

Does that mean that my SQL is already getting the Identity number from the table?
 
Back
Top