문제

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