retriving autoincrement value after insert command

  • Thread starter Thread starter Mauro Gagna
  • Start date Start date
M

Mauro Gagna

hi, i have a table with customers and the customer ID is an
autoincrement field in SQLServer 2000.

I'm using this code (small version of the real code) to do an insert
into this table

OleDbConnection conn = ConnectToDataBase(); // Call to my DB
connection funtion
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "INSERT INTO customers (name, phone) values
(@strName, @strPhone)";
cmd.Parameters.Add("@name", "john");
cmd.Parameters.Add("@phone", "555-0002");
cmd.ExecuteNonQuery();

the problem is how can i know what is the customer ID that the
SQLServer assigns to this record. I have multiple users that are doing
inserts in the same time.

Thanks in advace.

Mauro Gagna
(e-mail address removed)
 

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

Back
Top