Domanda

Dear data spacial lord if there's one listening to my plea,

My code looks like this,

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();

It passed authentication/authorization, but _table.columns.Count is zero, though db.Tables.Count has good value, so I'm wondering how _table can be populated.

Kindly please help, thanks.

Should there be any detail missed or any question, please do feel free to let me know.

È stato utile?

Soluzione

Once you hvae the Database, just inspect it's .Tables property:

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;
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top