Ado.net获取架构表 [英] Ado.net Getting the schema for a table

查看:188
本文介绍了Ado.net获取架构表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于你怎么可以得到单个表架构的SQLConnection对象?

Given an SQLConnection object how can you get a schema for a single table?

我是想这样的一天,我似乎能够得到它我会得到从运行查询的数据集的架构,但所有的架构信息,我可以得到从连接似乎与什么表可用​​,而不是在表中的实际细节

I was trying this the other day and I seemed to be able to get the schema from a DataSet which I'd gotten from running a query, but all the schema info I could get from the connection seemed to be related to what tables were available and not the actual details on the tables.

我敢肯定有一个简单的方法来做到这一点。

I'm sure there is a simple way to do this.

推荐答案

我觉得从查询(通过的GetSchemaTable)访问模式是做到这一点的唯一方法。 你可以跑不返回任何行的查询(从表中选择* 1 = 2)如果模式是所有你感兴趣的问题。

I think accessing the schema from the query (via GetSchemaTable) is the only way to do it. You can run a query which returns no rows (select * from table where 1=2) if the schema is all you're interested in.

您应该使用的密钥信息CommandBehaviour执行源查询,否则不是所有返回的信息是保证准确

You should use the KeyInfo CommandBehaviour to execute the source query, as otherwise not all the information returned is guaranteed to be accurate

Command.ExecuteReader(CommandBehavior.KeyInfo)

这篇关于Ado.net获取架构表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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