[英]manually increment id in c# from mysql
So I have make an order management system I have use this code to insert my order in data. 因此,我制作了一个订单管理系统,使用此代码将订单插入数据中。
xconn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "insert into tblOrder
(RegId,ItmId,quantity,Odrdate,Total) values ('" + label11.Text + "','" +
26 + "','" + txt26.Text + "','" + date + "','" + lbltotal.Text + "');";
cmd.Connection = xconn;
cmd.ExecuteNonQuery();
xconn.Close();
So the order id in my table is auto increment but I want it to only increment after one order is complete. 因此,我表中的订单ID是自动递增的,但是我希望它仅在完成一个订单后才递增。
Once I click total the odrid should increment so that next order gets a new id. 一旦我单击合计,odrid应该增加,以便下一个订单获得新的id。
You simply can not insert a new row into a database table without a unique id, if the id is the primary key. 如果id是主键,则根本无法将新行插入没有唯一ID的数据库表中。
Why dont you introduce a new column „order_status“ in which you store the state of the current order? 为什么不引入新的“ order_status”列来存储当前订单的状态?
Once I click total the odrid should increment so that next order gets a new id.
一旦我单击合计,odrid应该增加,以便下一个订单获得新的id。
What if a orderId is exist for example you click on 993 and you want 994 but it's already exists in database. 例如,如果存在orderId,该怎么办?例如,您单击993并想要994,但它已经存在于数据库中。
As Other suggested you can put a column that have information regarding your +1. 如其他建议一样,您可以在列中添加有关+1的信息。 If you are using your current code in production your code can easily hacked using SQL-Injection be careful.
如果您在生产中使用当前代码,请小心使用SQL-Injection轻松破解代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.