2011-01-19 3 views
0

外観:は、テーブルのスキーマを取得

public void GetScheme4Table(string tableName) 
{ 
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\" + DdListDatabases4GettingTables.SelectedValue + ".mdb;Persist Security Info=True"); 
    conn.Open(); 
    DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, 
                new object[] { null, null, null, tableName }); 
    GridViewTablesScheme.DataSource = schemaTable; 
    GridViewTablesScheme.DataBind(); 
    conn.Close(); 
} 

行は、私はこの問題を解決することができますどのようにスキーマのデータテーブルではありませんか?

テーブルのスキーマを取得して、gridviewに表示したいと考えています。

答えて

0

次のことを試してみてください。

public DataTable GetScheme4Table(string tableName) 
{ 
    DataTable ret = null; 
    IDbCommand command = null; 

    using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\" + DdListDatabases4GettingTables.SelectedValue + ".mdb;Persist Security Info=True")) 
    { 
     command = connection.CreateCommand(); 
     command.CommandText = string.Format("SELECT TOP 1 * FROM [{0}]", tableName); 
     using (IDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo)) 
     { 
      ret = reader.GetSchemaTable(); 
     } 
    } 

    return ret; 
} 
関連する問題