Reputation: 21
I have an ODBC connection using a DSN and I am trying to get the tables and columns from it (for manipulation later) but it is failing at an early stage. The database is a FairCom C-tree (v 6.11) if it matters:
OdbcConnection odbcConn = new OdbcConnection("DSN=Ctree;");
odbcConn.Open();
DataTable tblTables = odbcConn.GetSchema("Tables");
foreach (DataRow row in tblTables.Rows) //displays them one at a time (works)
MessageBox.Show(row["TABLE_NAME"].ToString());
DataTable tblColumns = odbcConn.GetSchema("Columns"); // (why is this empty?)
foreach (DataRow row in tblColumns.Rows) //lists nothing
MessageBox.Show(row["COLUMN_NAME"].ToString() + " : " + row["TABLE_NAME"].ToString());
The issue is that getSchema("Tables") works just fine so I know that the connection works, the drivers are in good shape and that data exists. So why is getSchema("Columns") failing? I also know there is data (hundreds of columns and thousands of rows) inside the db. I am at a loss.
Thoughts?
Upvotes: 1
Views: 1578
Reputation: 31
Unsure if this works with Faircom C-Tree SQL, but try getting the column schema for a single table.
GetSchema()
permits the specification of restrictions.
var restrictions = new string[] { null, null, "TableName" };
odbcConn.GetSchema("Columns", restrictions);
You may have to specify the schema name as well (e.g. Sales.SalesPeople)
var restrictions = new string[] { null, "Sales", "SalesPeople" };
odbcConn.GetSchema("Columns", restrictions);
Upvotes: 3