使用C#获取插入行的ID

使用C#获取插入行的ID,第1张

使用C#获取插入行的ID

[编辑:在引用last_insert_id()之前添加了“选择”]

select last_insert_id();
插入后运行“ ”怎么办?

MySqlCommand comm = connect.CreateCommand();comm.CommandText = insertInvoice;comm.CommandText += "'" + invoiceDate.ToString("yyyy:MM:dd hh:mm:ss") + "', "      + bookFee + ", " + adminFee + ", " + totalFee + ", " + customerID +  ");";    + "select last_insert_id();"int id = Convert.ToInt32(comm.ExecuteScalar());

编辑:
如duffymo所述,使用像这样的参数化查询确实可以很好地为您服务。


编辑: 在切换到参数化版本之前,您可能会发现string.Format和平:

comm.CommandText = string.Format("{0} '{1}', {2}, {3}, {4}, {5}); select last_insert_id();",  insertInvoice, invoiceDate.ToString(...), bookFee, adminFee, totalFee, customerID);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5043290.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存