数据库中有上万条数据需显示在dataGrid中,是winform程序。在显示时需很长时间才能显示出来。
请问各位有什么好的方法优化吗? 如像web程序那样分页显示。

解决方案 »

  1.   

    首先,设置一个主键,假如为KeyCol,类型为int,
    查询时,用:
    declare @pagenum int --每页的行数
    delcare @CurPage int --当前的页数
    selecct top @pagennum * from tablename where keycol>@pagenum*@curpage
    ordey by keycol
    以上是伪代码,给你提供一个思路
      

  2.   

    写一段筛选数据的代码,只有在需要数据时才把数据加载到数据集里。数据集里无关的数据要及时清除,减少内存占用。
    再有就是,可以和DataView配合使用。
      

  3.   

    使用 Visual C# .NET 对 DataGrid Windows 控件执行分页
    http://support.microsoft.com/default.aspx?scid=kb;zh-cn;307710
      

  4.   

    可以用存储过程每页,分批取数据
    CREATE procedure DocSearchtest
     @PageIndex INT,
         @PageSize  INT,
         @RecordCount INT OUT,
         @PageCount INT OUT,
    @DocName varchar(100),
    @KeyWord varchar(50),
    @UserName varchar(16)
    as
    begin
    SELECT @RecordCount = COUNT(*)  FROM   MyDoc_TSET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize) 
    declare @indextable table(id int identity(1,1),nid int)  --定义表变量
    declare @PageLowerBound int  --定义此页的底码
    declare @PageUpperBound int  --定义此页的顶码
    set @PageLowerBound=@pageindex*@pagesize
    set @PageUpperBound=@PageLowerBound+@pagesize
    set rowcount @PageUpperBound
    insert into @indextable(nid)  select Docid from MyDoc_T where DocName like @DocName and KeyWord like @KeyWord and UserName like @UserName
    select d.Docid,d.DocName,d.TypeName,d.ShareType,d.CDate,d.KeyWord,d.UserName,d.Fname from MyDoc_T d ,@indextable t
    where (d.Docid=t.nid)
    and t.id>@PageLowerBound and t.id<=@PageUpperBound 
    end
    GO
      

  5.   

    参看
    http://blog.csdn.net/knight94/archive/2006/03/23/635885.aspx