示例#1
0
        /// <summary>
        /// 根据标识列的值返回整条数据
        /// </summary>
        /// <param name="IdentityValue">标识列的值</param>
        /// <returns></returns>
        internal DataTable SelectByIdentity(string IdentityValue)
        {
            string strTable     = "";
            string strCondition = "";

            try
            {
                //获取表名
                strTable = InternalBase <T> .GetTableName();

                //获取条件
                PropertyInfo[] pi = typeof(T).GetProperties();
                foreach (var item in pi)
                {
                    var temp = InternalBase <T> .GetColumnAttribute(item);

                    if (temp.Identity)
                    {
                        strCondition = item.Name + "='" + IdentityValue + "'";
                        break;
                    }
                }
                string sql = string.Format("select * from {0} where {1}", strTable, strCondition);
                return(dbl.ExecuteQuery(sql));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// 查询返回所有数据,根据字典生成条件,用于时间条件为时间段时.
        /// </summary>
        /// <param name="dic">保存条件的字典,key为字段名称,关键字:数据库字段名__q(时间起),数据库字段名__z(时间止),数据库字段名__or(条件为or),数据库字段名__like(查询为like)</param>
        /// <param name="order">排序字段:如果不需要排序可不传入数据,也可以传入null或者"";如果需要排序则写入order by之后的内容</param>
        /// <param name="tableName">表名</param>
        /// <param name="columnName">列名,默认为*,查询所有</param>
        /// <returns></returns>
        public DataTable Select(Dictionary <string, object> dic, string order = "", string tableName = "", string columnName = "*")
        {
            string sql = string.Empty;

            try
            {
                string strTable = InternalBase <T> .GetTableName(tableName);

                string strCondition = InternalBase <T> .GetConditionByDIC(dic);

                string strOrder = InternalBase <T> .AddOrder(order);//获取排序字段

                sql = string.Format("select {0} from {1} {2} {3}", columnName, strTable, strCondition, strOrder);
                return(dbl.ExecuteQuery(sql));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, sql);
                return(null);
            }
        }
示例#3
0
        /// <summary>
        /// 查询返回所有数据,根据实体对象生成条件.
        /// </summary>
        /// <param name="t">实体类,将查询条件赋给实体类的属性</param>
        /// <param name="order">排序字段:如果不需要排序可不传入数据,也可以传入null或者"";如果需要排序则写入order by之后的内容</param>
        /// <param name="columnName">列名,默认为*,查询所有</param>
        /// <returns></returns>
        public DataTable Select(T t, string order = "", string columnName = "*")
        {
            string sql = string.Empty;

            try
            {
                string strTable = InternalBase <T> .GetTableName();

                string strCondition = InternalBase <T> .GetParamForSelectAndDelete(t);

                string strOrder = InternalBase <T> .AddOrder(order);//获取排序字段

                sql = string.Format("select {0} from {1} {2} {3}", columnName, strTable, strCondition, strOrder);
                return(dbl.ExecuteQuery(sql));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, sql);
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// 根据sql语句进行查询,返回唯一的字符串
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns></returns>
        public string GetOnlyColumnValue(string sql)
        {
            DataBaseLayer dbl = new DataBaseLayer();
            DataTable     dt  = dbl.ExecuteQuery(sql);

            if (dt.Rows.Count > 0)
            {
                return(dt.Rows[0][0].ToString());
            }
            else
            {
                return("");
            }
        }
示例#5
0
 /// <summary>
 /// 根据sql语句进行查询,返回数据
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <returns></returns>
 public DataTable SelectBySQL(string sql)
 {
     return(dbl.ExecuteQuery(sql));
 }