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

后端 未结 3 385
野趣味
野趣味 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:10

    DataTable has Columns property and DataColumn has a property indicating auto-increment:

    bool isAutoIncrement = dataTable.Columns[iCol].AutoIncrement
    

提交回复
热议问题