Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top