在给定数据库名称的情况下检索表名称 [英] retrieve table names given a database name

查看:131
本文介绍了在给定数据库名称的情况下检索表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序来在C#中的db中添加/编辑表中的表项.

我想知道是否可以通过给定数据库名称来检索表名称,例如northwind.

在这方面,请帮我,因为我一直坚持下去.

在此先感谢.

I am writing a program to add/edit table enteries in a db in c#

I want to know whether we will be able to retrieve table names given a database name,say northwind.

please help me in this regard,as i am stuck with it.

Thanks in advance.

推荐答案

以下内容将在大多数RDBM服务器上起作用:
The following will work on most RDBM servers :
select *
from INFORMATION_SCHEMA.TABLES



返回的实际列可能因服务器类型而异,但核心列TABLE_NAME等都存在.



The actual columns returned might vary between server types but the core ones TABLE_NAME etc. exist in all.


Try:
Try:
using (SqlConnection con = new SqlConnection(strCon))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.sysobjects WHERE xtype = 'U'", con))
        {
        using (SqlDataReader r = cmd.ExecuteReader())
            {
            while (r.Read())
                {
                Console.WriteLine(r["name"]);
                }
            }
        }
    }


这篇关于在给定数据库名称的情况下检索表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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