Exemplo n.º 1
0
        /// <summary>
        /// 获取DataSet  带排序
        /// </summary>
        /// <param name="typedb">数据库连接对象</param>
        /// <param name="selectTarget">查询对象</param>
        /// <param name="columns">查询的列</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="page">当前页</param>
        /// <param name="rowsPerPage">页面显示记录数 小于等于0 不分页</param>
        /// <param name="tolalCount">返回记录集合</param>
        /// <returns></returns>
        public DataSet GetDataSetOrderBy(DataBaseHelper.typedb typedb, string selectTarget, string columns, string strWhere, string orderBy, int page, int rowsPerPage, out int tolalCount)
        {
            //查询条件
            if (strWhere != "" && strWhere != null && strWhere != "null")
            {
                strWhere = " where " + strWhere;
            }
            else
            {
                strWhere = "";
            }

            //调用查询数据的方法。
            string strSQL = GetListSQL(selectTarget, columns, rowsPerPage, page, orderBy, strWhere);

            //组织获取记录数SQL
            string strTotalSQL = "select count(1) from " + selectTarget + strWhere;;

            //创建连接的数据库
            Database dbbase = DataBaseHelper.CreateDataBase(typedb);

            using (DbCommand cmd = dbbase.GetSqlStringCommand(strTotalSQL))
            {
                tolalCount = Convert.ToInt32(dbbase.ExecuteScalar(cmd));
            }
            //接收返回的结果数据。
            DataSet ds = null;

            using (DbCommand cmd = dbbase.GetSqlStringCommand(strSQL))
            {
                ds = dbbase.ExecuteDataSet(cmd);
            }
            return(ds);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取DataSet    groupby排序
        /// </summary>
        /// <param name="typedb">数据库连接对象</param>
        /// <param name="selectTarget">查询对象</param>
        /// <param name="columns">查询的列</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="page">当前页</param>
        /// <param name="rowsPerPage">页面显示记录数 小于等于0 不分页</param>
        /// <param name="tolalCount">返回记录集合</param>
        /// <returns></returns>
        /// <returns></returns>
        public DataSet GetDataSetGroupBy(DataBaseHelper.typedb typedb, string selectTarget, string columns, string strWhere, string orderBy, string gruopby, int page, int rowsPerPage, out int tolalCount)
        {
            //查询条件

            //if (strWhere != "")
            //**************修改 日期:2014-1-9  修改 人 王桑

            if (strWhere != "" && strWhere != null && strWhere != "null")
            {
                strWhere = " where " + strWhere;
            }
            else
            {
                strWhere = "";
            }
            if (gruopby != "" && gruopby != null && gruopby != "null")
            {
                gruopby = " group by  " + gruopby;
            }
            else
            {
                gruopby = "";
            }

            string strSQL = GetListSQLS(selectTarget, columns, rowsPerPage, page, orderBy, strWhere, gruopby);

            //组织获取记录数SQL
            //string strTotalSQL = "select count(1) from " + selectTarget + strWhere + gruopby;
            string strTotalSQL = "SELECT count(1) FROM " + selectTarget + " "
                                 + strWhere + " " + gruopby + " " + strOrderBy;
            Database dbbase = DataBaseHelper.CreateDataBase(typedb);

            using (DbCommand cmd = dbbase.GetSqlStringCommand(strTotalSQL))
            {
                DataTable dt = dbbase.ExecuteDataSet(cmd).Tables[0];
                //添加判断如果查询不到的时候进行验证 2016年4月1日20:52:45 王岩松
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows.Count == 1)
                    {
                        tolalCount = int.Parse(dt.Rows[0][0].ToString());
                    }
                    else
                    {
                        tolalCount = dt.Rows.Count;
                    }
                    //tolalCount = int.Parse(Convert.ToString(dbbase.ExecuteScalar(cmd)));
                }
                else
                {
                    tolalCount = 0;
                }
            }
            DataSet ds = null;

            using (DbCommand cmd = dbbase.GetSqlStringCommand(strSQL))
            {
                ds = dbbase.ExecuteDataSet(cmd);
            }
            return(ds);
        }