1个回答
展开全部
//C#获取Access数据库中的所有表名和列名
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=E:\report20100819\report20100819.mdb"; OleDbConnection Conn = new OleDbConnection(ConnectionString); Conn.Open();DataTable shemaTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); foreach (DataRow dr in shemaTable.Rows) { Console.WriteLine(dr["TABLE_NAME"]); DataTable columnTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null }); foreach (DataRow dr2 in columnTable.Rows) { Console.WriteLine(dr2["COLUMN_NAME"]); } } Conn.Close();
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=E:\report20100819\report20100819.mdb"; OleDbConnection Conn = new OleDbConnection(ConnectionString); Conn.Open();DataTable shemaTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); foreach (DataRow dr in shemaTable.Rows) { Console.WriteLine(dr["TABLE_NAME"]); DataTable columnTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null }); foreach (DataRow dr2 in columnTable.Rows) { Console.WriteLine(dr2["COLUMN_NAME"]); } } Conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |