【发布时间】:2015-08-12 10:01:12
【问题描述】:
如何编写代码以获取给定数据库中链接文本框的表数?我正在使用 Visual Studio 2013,对此我很陌生。我使用数据库服务器 ms sql。
public static List<string> GetTables(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
DataTable schema = connection.GetSchema("Tables");
List<string> TableNames = new List<string>();
foreach (DataRow row in schema.Rows)
{
TableNames.Add(row[0].ToString());
}
return TableNames;
}
}
【问题讨论】:
-
Database_Name.information_schema.tables -
你的代码有什么问题?为什么
schema.Rows.Count不是您问题的答案? -
你能给我计数码吗
-
@sweatbar:是的,没问题:
int tableCount = schema.Rows.Count;
标签: c# .net sql-server