有要实现分爷,又要实现搜索。
我想先搜索出个TABLE然后再在TABLE中实现分页。
结果一大对语法越弄越复杂,最后以失败告终。

组长实现的方法:
 public DataTable ShowPagesea(string searchType, int PageIndex, int PageSize, string DataTable, string searchValue)
        {
            string sqlWhere = "";
            switch (searchType)
            {
                case "RealName":
                    sqlWhere = "and RealName like '%" + searchValue + "%'";
                    break;
                case "DTitle":
                    sqlWhere = "and Dtitle like '%" + searchValue + "%'";
                    break;
                case "TDtype":
                    sqlWhere = "and TDtype='" + searchValue + "'";
                    break;
                case "all":
                    sqlWhere = "";
                    break;
                default:
                    break;
            }
            string sql = "select top " + PageSize + " * from " + DataTable + " where Did Not in (select top " + (PageIndex - 1) * PageSize + " Did from " + DataTable + " where 1=1 " + sqlWhere + " order by Did desc) " + sqlWhere + " order by Did desc ";
            DataTable dt = sdh.dbODSGetDataTable(sql, DataTable);
            return dt;
        }
 public int ShowPageCountsea(string searchType, string DataTable, string searchValue)
        {
            string sqlWhere = "";
            switch (searchType)
            {
                case "RealName":
                    sqlWhere = " where RealName like '%" + searchValue + "%'";
                    break;
                case "DTitle":
                    sqlWhere = " where Dtitle like '%" + searchValue + "%'";
                    break;
                case "TDtype":
                    sqlWhere = " where TDtype='" + searchValue + "'";
                    break;
                case "all":
                    sqlWhere = "";
                    break;
                default:
                    break;
            }
            string sql = "select count(*) from " + DataTable + sqlWhere;
            int i = Convert.ToInt32(sdh.dbExecuteSql4Value(sql));
            if (i % 10 == 0)
            {
                i = i / 10;
            }
            else
            {
                i = i / 10 + 1;
            }
            return i;
        }
直接把判断加进去,两个条件同时进行判断。实现了功能。
posted on 2007-09-03 11:41  超少  阅读(219)  评论(0编辑  收藏  举报