Powershell 中的last_insert_id

发布于 2024-12-04 10:34:09 字数 501 浏览 5 评论 0原文

在 Powershell 中,我有一个简单的 Mysql 插入命令。

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

我正在使用 Mysql Connector Net 6.2.4。

是否可以返回 last_insert_id() 或类似的内容?

我在这里查找了一些信息,但找不到任何东西。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-12-11 10:34:09

不是有一个 $command.LastInsertedId 属性吗?如果没有,您可以随时发出 SELECT LAST_INSERT_ID() 查询。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文