簡體   English   中英

什么是在MySQL中使用scope_identity(),@@ identity(),last_insert_id()的正確版本

[英]whats the right version for using either scope_identity() ,@@identity (),last_insert_id() in mysql

我在asp.net c#上工作,我嘗試了所有3個但都沒有工作,這是sql錯誤(您的SQL語法有錯誤;請檢查與您的MySQL服務器版本相對應的手冊,以在附近使用正確的語法'SELECT LAST_INSERT_ID()')這是我的查詢:

                String st = ("INSERT INTO `service` VALUES ('','" + noms + "','" + Desc + "','3','" + ad + "','" + vil + "','" + pays + "')"+" SELECT SCOPE_IDENTITY()");

您可以像這樣使用MySqlCommand LastInsertedId屬性:

// cmd is MySqlCommand objet
cmd.ExecuteNonQuery();
long lastInsertedId = cmd.LastInsertedId;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM