c#读取access中指定表的字段名及其描述///<summary>
///获取指定表名的列名与描述注释
///</summary>
///<param name="mdbFilePath"></param>
///<param name="tableName"></param>
///<returns></returns>
public static Hashtable GetTableFieldsDisFromMdb(string mdbFilePath, string tableName)
{
Hashtable tableFields = new Hashtable();
try
{
ADOX.CatalogClass cat = new ADOX.CatalogClass();
string sAccessConnection = strConnRoot + mdbFilePath;
ADODB.Connection cn = new ADODB.Connection();
cn.Open(sAccessConnection, null, null, -1);
cat.ActiveConnection = cn;
ADOX.Table tb = cat.Tables[tableName];
if (tb!=null)
{
foreach (ADOX.Column col in tb.Columns)
{
string colName = col.Name.ToString();
string colDis = "";
foreach (ADOX.Property pro in col.Properties)
{
if (pro.Name == "Description")
{
if (pro.Value != null) colDis = pro.Value.ToString();
break;
}
param name
}
tableFields.Add(colName, colDis);
}
}
cat = null;
cn.Close();
}
catch (System.Exception ex)
{
return tableFields;
}
return tableFields;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。