How can I determine in C# whether a SQL Server database column is autoincrement?

后端 未结 3 416
野趣味
野趣味 2021-01-05 19:47

I need to be able to determine from the DataTable returned by DbConnection.GetSchema() whether a particular column in a SQL Server table is identity/auto-increment or not.

3条回答
  •  滥情空心
    2021-01-05 20:23

    I have run into the same. As far as I discovered here "An auto increment column is implemented differently depending upon the type of database you are working with. It isn't exposed via GetOleDbSchema.".

    I didn't find any other way than @kelloti mentioned. So at the moment I'm fine with this solution because at the moment I need to know if column is .AutoIncrement. I already have the table in memory so I don't need to query the database again.

    @pesaak Please convert this answer into a comment now that you should have enough reputation.

提交回复
热议问题