栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用C#获取插入行的ID

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用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);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/416441.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号