亲爱的数据空间主,如果有人听我的请求,
我的代码看起来像这样,
string ConnectionString = "Data Source=AServerName;Initial Catalog=ADBName;Integrated Security=SSPI;";
string TableName = "ATableName";
string SchemaName = "dbo";
Server server = new Server(new ServerConnection(new SqlConnection(ConnectionString)));
SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
Database db = new Database(server, connectionStringBuilder.InitialCatalog);
db.Refresh();
Table _table = new Table(db, TableName, SchemaName);
_table.Refresh();
它通过了身份验证/授权,但_table.columns.Count
为零,但db.Tables.Count
具有良好的价值,所以我想知道如何填充_table 。
请帮助,谢谢。
如果遗漏任何细节或有任何疑问,请随时告诉我。
答案 0 :(得分:2)
获得Database
后,只需检查.Tables
财产:
Database db = new Database(server, connectionStringBuilder.InitialCatalog);
db.Refresh();
foreach(var table in db.Tables)
{
// do something with each table here...
string tableName = table.Name;
foreach(var column in table.Columns)
{
// do something with each column for that table
string columnName = column.Name;
}
}