如何使用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#)[^]