当前位置:编程学习 > C#/ASP.NET >>

得到MDB文件中的表名个字段名、字段类型名称

C# 代码
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|aspxWeb2.mdb;";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
DataTable schemaTable;
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
for (int i = 0; i < dt.Rows.Count; i++)
{
  String tableName = dt.Rows[i]["TABLE_NAME"].ToString();
  Response.Write("<h1>" + tableName + "</h1>");
  schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new Object[] { null, null, tableName, null });
  for (int j = 0; j < schemaTable.Rows.Count; j++)
  {
    Response.Write("<li>字段名称:" + schemaTable.Rows[j]["COLUMN_NAME"].ToString() + " 类型:" + (OleDbType)schemaTable.Rows[j]["DATA_TYPE"] + "</li>");
  }
}
conn.Close();


作者  孟宪会
 
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,