gpt4 book ai didi

c# - 在C#中如何确定SQL Server数据库列是否自动增量?

转载 作者:行者123 更新时间:2023-12-03 01:59:20 25 4
gpt4 key购买 nike

我需要能够从 DbConnection.GetSchema() 返回的 DataTable 确定 SQL Server 表中的特定列是否是标识/自动增量。我无法直接查询系统表。

奇怪的是,如果我通过 ODBC 连接到 SQL Server,则此类列的返回数据类型将返回为“int Identity”(或“bigint Identity”等),但如果我使用 native SQL Server 驱动程序,则会出现“int”列和“int Identity”列之间没有区别。有其他方法可以推断出该信息吗?

最佳答案

DataTable 具有 Columns 属性,DataColumn 具有 a property表示自动递增:

bool isAutoIncrement = dataTable.Columns[iCol].AutoIncrement

关于c# - 在C#中如何确定SQL Server数据库列是否自动增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4834592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com