0

I want to get primarykey ID of just insert item. In PHP has mysql_insert_id(). I write in C#

Prince OfThief
  • 6,075
  • 13
  • 38
  • 52

2 Answers2

1

You have to query the database directly.

SELECT last_insert_id() FROM mytable;

So say with ODBC

object lastID = new OdbcCommand("SELECT last_insert_id() FROM mytable", _connection).ExecuteScalar();
Novikov
  • 4,243
  • 2
  • 22
  • 36
1

If cmd is your command object try:

  cmd.LastInsertId;
Adrian Serafin
  • 7,427
  • 5
  • 44
  • 65