How can I enable auto increment primary key in c# when connected to database in mysql? I'm looking for a way when I add a data to the database using C# it will automatically give me an ID that will be in order. For example I am a manager in a company and I want to add a new item that I do't need to enter the id.

有帮助吗?

解决方案

That is normally the database's job. Set column for the ID to be auto incrementing. Write the query in such a way that it rereads the just inserted row (as a stored procedure or as an insert/select pair). Now you have your unique ID right after insert. HTH

其他提示

You can set Id column in database as Auto Increment you don't need to do it from C#. if you want to do it then select the last inserted Id and then add your static increment mask to it and then insert this new Id to database.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top