0

I need to insert a row and use that "last id" immediately so I need to execute a query like this

INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
SELECT LAST_INSERT_ID();

I know that to INSERT I must call cmd.ExecuteNonQuery() and to SELECT I call cmd.ExecuteReader()

But how to do both in a single query?

Chayanin
  • 281
  • 1
  • 5
  • 11

1 Answers1

0

Try the following after insert query:

SELECT MAX(id) FROM tablename;

or

SELECT fields FROM table ORDER BY id DESC LIMIT 1;