日期:2014-05-20  浏览次数:20430 次

几十万的数据用什么办法能最快读取
几十万的数据用什么办法能最快读取,还要分页的,分页跟百度一样

------解决方案--------------------
那么多的数据不可能全部读到dataset中再处理,那样要消耗多少内存啊!
建议DataReader分页(c#)
#region 分页
//intPageSize 每页显示记录数
//intPageIndex 当前显示第几页
//strTable 你要处理的那个数据库表名
//strField 要取那些字段 字段间用“,”隔开 *是全部
//strSortField 按哪个字段排序 无就为空
//strSQL_Where 你要做的那个sql语句where后面的字符串 无就为空
//boolSort 是否要排序 true为降序,boolSort=false为升序
//intRecordCount 共多少条记录

public SqlDataReader FY_SQLCommand(int intPageSize, int intPageIndex, string strTable, string strField, string strSortField, string strSQL_Where, bool boolSort, int intRecordCount)
{
int intItemCount = intRecordCount - intPageSize * intPageIndex;
if (intItemCount < 0) intItemCount = intItemCount + intPageSize;
else intItemCount = intPageSize;
string strSQL;
if (strSQL_Where != " ") strSQL = "select " + strField + " from " + strTable + " where " + strSQL_Where;
else strSQL = "select " + strField + " from " + strTable;
if (boolSort) strSQL = "SELECT " + strField + " FROM (SELECT TOP " + intItemCount.ToString() + " " + strField + " FROM (SELECT TOP " + (intPageSize * intPageIndex).ToString() + " " + strField + " FROM ( " + strSQL + ") AS T0 ORDER BY " + strSortField + " DESC) AS T1 ORDER BY " + strSortField + " ASC) AS T2 ORDER BY " + strSortField + " DESC ";
else strSQL = "SELECT " + strField + " FROM (SELECT TOP " + intItemCount.ToString() + " " + strField + " FROM (SELECT TOP " + (intPageSize * intPageIndex).ToString() + " " + strField + " FROM ( " + strSQL + ") AS T0 ORDER BY " + strSortField + " asc) AS T1 ORDER BY " + strSortField + " desc) AS T2 ORDER BY " + strSortField + " asc ";
return GetReader(strSQL);
//此处GetReader()是我写的一个方法,你自己实现好了,它的功能就是通过一句sql语句生成一个DataReader
}
#endregion