使用SqlConnection.GetSchema拿到仅有的表(无查看) [英] Use SqlConnection.GetSchema to get Tables Only (No Views)

查看:1360
本文介绍了使用SqlConnection.GetSchema拿到仅有的表(无查看)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

SqlConnection.GetSchema("Tables");

它返回的所有表和视图的目标数据库。

it returns all the tables AND views for the target database.

有没有什么办法可以只返回表?所有的研究我已经做了说明我正确地做这个但它总是返回的意见,就像他们是表。我已经挖成在调试DataTable中,我甚至不能找到一个差异。该数据类型的报道一致......至于我可以告诉大家,它不是一个视图和表之间的区别。 (这有一定道理的方式,因为对于所有意图和目的视图是一个表。)

Is there any way to just return tables? All the research I have done indicates I am doing this correctly yet it always returns the views like they are tables. I have dug down into the DataTable in debug and I can't even find a difference. The data types are reported the same... As far as I can tell, it can't differentiate between a view and a table. (It does make sense in a way since a view for all intents and purposes IS a table.)

我使用Northwind数据库进行测试。

I am using the Northwind database for testing.

我写在C#应用程序。

下面是我正在获取架构信息的code。 pretty的简单。

Here is the code that I am running to get the schema info. Pretty simple.

SQLCon.Open();
DataTable tables = SQLCon.GetSchema("Tables");
SQLCon.Close();

我就非常喜欢用GetSchema方法,而不必在查询另一种方式的数据库...如果可能的话。

I would very much like to use the getschema method and not have to query the database in another fashion... if at all possible.

推荐答案

根据这篇文章,返回的数据表中有一栏 TABLE_TYPE ,它告诉你它是否是一个查看或一个基表
使用该列中筛选出在C#结束的观点。

According to this article, the returned data table has a column table_type, which tells you whether it's a VIEW or a BASE TABLE.
Use that column to filter out the views on your C# end.

这篇关于使用SqlConnection.GetSchema拿到仅有的表(无查看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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