Exemple #1
0
        /// <summary>
        /// 根据条件查询表
        /// </summary>
        /// <param name="dbHelper">数据库帮助类</param>
        /// <param name="tableStructure">表结构</param>
        /// <param name="fieldName">条件筛选的字段</param>
        /// <param name="fieldValue">条件筛选的字段值,可空</param>
        /// <param name="orderbyString">排序语句,此值为null时根据UPDATEDATE排序</param>
        /// <returns></returns>
        public static DataTable QueryTable(DbHelper dbHelper, TableStructure tableStructure, string fieldName, string fieldValue, string orderbyString)
        {
            FieldClass fieldClass = tableStructure.Fields.FirstOrDefault(v => v.Name == fieldName);

            return(QueryTable(dbHelper, tableStructure, fieldClass, fieldValue, orderbyString));
        }
Exemple #2
0
        /// <summary>
        /// 根据条件查询表
        /// </summary>
        /// <param name="dbHelper">数据库帮助类</param>
        /// <param name="tableStructure">表结构</param>
        /// <param name="fieldClass">条件筛选的字段</param>
        /// <param name="fieldValue">条件筛选的字段值,可空</param>
        /// <param name="orderByString">排序语句,此值为null时根据UPDATEDATE排序</param>
        /// <returns></returns>
        public static DataTable QueryTable(DbHelper dbHelper, TableStructure tableStructure, FieldClass fieldClass, string fieldValue, string orderByString)
        {
            string whereClause = null;

            if (!string.IsNullOrEmpty(fieldValue))
            {
                if (fieldClass.FieldType == typeof(string))
                {
                    whereClause = $"{fieldClass.Name} like '%{fieldValue}%'";
                }
                else if (fieldClass.FieldType == typeof(DateTime))
                {
                    whereClause = $"{fieldClass.Name} = #{fieldValue}#";
                }
                else
                {
                    whereClause = $"{fieldClass.Name} = {fieldValue}";
                }
            }
            return(QueryTable(dbHelper, tableStructure, whereClause, orderByString));
        }
Exemple #3
0
 /// <summary>
 /// 向表结构中添加字段信息
 /// </summary>
 /// <param name="fieldClass"></param>
 public void AddField(FieldClass fieldClass)
 {
     this.Fields.Add(fieldClass);
 }