1

In Powershell, I have a simple Mysql insert command.

$query = "INSERT INTO TABLE1 (id, col1, col2) VALUES (1, 'two', 'three');"<br>
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $connection)
$command.ExecuteNonQuery()

I'm using Mysql Connector Net 6.2.4.

Is it possible to return the last_insert_id() or something similar?

I've looked here for some info but can't really find anything.

Any thoughts?

Shef
  • 44,808
  • 15
  • 79
  • 90
steve
  • 849
  • 2
  • 9
  • 15

1 Answers1

2

Isn't there a $command.LastInsertedId property? If not you can always issue a SELECT LAST_INSERT_ID() query.

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189