[编辑:在引用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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)