get the next auto increment

  • Thread starter Thread starter Grant
  • Start date Start date
G

Grant

I am using MySqlCommand which I am sure it is the same as SqlCommand. I
have a column in the table that auto increment when a record is added into
the table. How can I execute an insert statement into a table and get the
new id number that auto increment at the same time.



Thanks.
 
I guess you are using SQL Server..

You can throw this at the end of your query
Select @id = @@IDENTITY

And then pull @id out with an output parameter from your command object.
 
No, I am using MYSql but I will try it tomorrow to see if it works for
MySql. Thanks.

I guess you are using SQL Server..

You can throw this at the end of your query
Select @id = @@IDENTITY

And then pull @id out with an output parameter from your command object.
 
Back
Top