2

亲爱的数据空间领主,如果有人在听我的请求,

我的代码看起来像这样,

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

请帮忙,谢谢。

如果有任何细节遗漏或任何问题,请随时告诉我。

4

1 回答 1

2

一旦你 hvae 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;
   }
}
于 2013-08-07T19:42:37.747 回答