如何使用asp.net获取数据库表 [英] How to get database tables using asp.net

查看:72
本文介绍了如何使用asp.net获取数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net中获取数据库然后在它上面循环获取表格

i知道这段代码但是我不知道如何使用它



数据库db = sv.Databases [Database_Name];这个获取数据库



TableCollection tables = db.Tables;这是获取表格

i want to get database in asp.net then loop on it to get tables
i know this code but i dont know how to use it

Database db = sv.Databases["Database_Name"]; this to get database
and
TableCollection tables = db.Tables; this to get tables

推荐答案

以下是从数据库中获取所有表格的方式:



Here is the way you get all the tables from a database :

public static List<string> GetDBTables(string connectionString)
{
    using (SqlConnection con = new SqlConnection(connectionString))
    {
        con.Open();
        DataTable dtschema = con.GetSchema("Tables");
        List<string> TableNames = new List<string>();
        foreach (DataRow row in dtschema.Rows)
        {
            TableNames.Add(row[2].ToString());
        }
        return TableNames;
    }
}





参考



从服务器C上的特定数据库中检索表列表# [ ^ ]



希望它有所帮助。

祝你好运。



Reference

Retrieve List of Tables from Specific Database on Server C#[^]

Hope it helps.
Good luck.

试试这个.. :)



从服务器C#上的特定数据库中检索表的列表 [ ^ ]



如何获取MSSQL数据库的所有表? [ ^ ]



如何在C#中查找数据库中的表格 [ ^ ]



获取Access数据库(C#)中的表列表 [ ^ ]
try this.. :)

Retrieve List of Tables from Specific Database on Server C#[^]

How to get all tables of a MSSQL-Database?[^]

How to find tables in a Database in C#[^]

Getting a list of tables in an Access database (C#)[^]


这篇关于如何使用asp.net获取数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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