Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Get ID after Inserting (2 replies)

$
0
0
Hi,

I'm using the .NET-Connector with C#. I have a question about how to get an auto-incremented primaykey value after inserting data.

Therefore i've got a table like this:
CREATE TABLE `images` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` TEXT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`id`)
);

Now i'm inserting a row like this:
command = connection.CreateCommand();
command.CommandText = "INSERT INTO `images` (`id`, `name`) VALUES (NULL, 'test');";
MySqlDataReader result = command.ExecuteReader();

How can i get the newly generated id? (Also in case there are more datasets with name "test".)

regards cm

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>