Ejemplo n.º 1
0
    /// <summary>
    /// 得到Access列的描述
    /// </summary>
    /// <param name="TableName">表名</param>
    /// <param name="ColumnName">列名</param>
    public static string GetColumnDescription(string TableName, string ColumnName)
    {
        //Caption
        //ColumnHidden
        //ColumnOrder
        //ColumnWidth
        //DecimalPlaces
        //Description
        //Format
        //InputMask
        const int dbUseJet = 2;
        String    dbName   = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings["DbPath"].ToString());

        DAO.Workspace DAOWorkspace;
        DAO.Database  DAODatabase;
        DAO.DBEngine  DAODBEngine = new DAO.DBEngine();
        // 创建一个工作区
        DAOWorkspace = DAODBEngine.CreateWorkspace(" WorkSpace ", "admin", null, dbUseJet);

        // 打开数据库
        DAODatabase = DAOWorkspace.OpenDatabase(dbName, false, false, null);
        DAO.TableDef DAOTable;
        DAO.Field    DAOField;

        // 表对象
        DAOTable = DAODatabase.TableDefs[TableName];
        DAOField = DAOTable.Fields[ColumnName];

        return(DAOField.Properties["Description"].Value.ToString());
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取表属性字段描述字典
        /// </summary>
        /// <param name="dbPath">数据文件路径</param>
        /// <param name="tbName">表名</param>
        /// <returns></returns>
        public static Dictionary <string, string> GetFieldDescriptions(string dbPath, string tbName)
        {
            try
            {
                const int dbUseJet = 2;

                dao.Workspace DAOWorkspace;
                dao.Database  DAODatabase;
                dao.DBEngine  DAODBEngine = new dao.DBEngine();
                //创建一个工作区
                DAOWorkspace = DAODBEngine.CreateWorkspace("WorkSpace", "Admin", "", dbUseJet);

                //打开数据库
                DAODatabase = DAOWorkspace.OpenDatabase(dbPath, false, false, null);
                dao.TableDef DAOTable;

                Dictionary <string, string> fieldCaptionDic = new Dictionary <string, string>();
                // 表对象
                DAOTable = DAODatabase.TableDefs[tbName];
                foreach (dao.Field field in DAOTable.Fields)
                {
                    //读取 UserName 字段的 “标题”属性,如果标题没有设置,则会抛出异常。
                    //如果标题不存在,我们就添加一个标题
                    String descriptionText;
                    try
                    {
                        descriptionText = field.Properties["Description"].Value.ToString();
                    }
                    catch
                    {
                        descriptionText = field.Name;
                    }
                    fieldCaptionDic.Add(field.Name, descriptionText);
                }
                DAODatabase.Close();

                return(fieldCaptionDic);
            }
            catch
            {
                return(null);
            }
        }