我如何在C#中确定一个SQL Server数据库列是否是自动增量? [英] How can I determine in C# whether a SQL Server database column is autoincrement?

查看:480
本文介绍了我如何在C#中确定一个SQL Server数据库列是否是自动增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从()由DbConnection.GetSchema返回的数据表在SQL Server表中的特定列是否标识/自动增量与否来决定。我不能诉诸直接查询系统表。

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. I cannot resort to querying the system tables directly.

奇怪的是,如果我通过ODBC连接到SQL Server,对于这样的列返回的数据类型返回为INT身份(或BIGINT身份等)但如果我使用本地SQL Server驱动程序,似乎是一个INT栏和INT标识列之间没有区别。有一些其他的方式,我可以推断出这些信息?

Oddly, if I connect to SQL Server via ODBC, the returned datatype for such a column is returned as "int identity" (or "bigint identity", etc.) but if I use the native SQL Server driver, there appears to be no distinction between an "int" column and an "int identity" column. Is there some other way I can deduce that information?

推荐答案

数据表属性和的DataColumn 拥有的属性指示自动递增:

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

bool isAutoIncrement = dataTable.Columns[iCol].AutoIncrement

这篇关于我如何在C#中确定一个SQL Server数据库列是否是自动增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆