如果在DataGrid中分页显示数据,每页30条,总共10000条记录,页面显示非常慢,简直让人无法忍受,各位大侠有没有遇到过这种情况啊???????

解决方案 »

  1.   

    用分页存储过程,每次只从数据库中取出30条,用这30条来邦定就行了关于分页存储过程,你可以到asp版块里去搜。
    用DataGrid自带的分页效率肯定不行。
      

  2.   

    可能是你分页存储过程写的有问题,参考下这个
    http://www.webdiyer.com/
      

  3.   

    http://blog.csdn.net/lindping/archive/2006/04/06/652217.aspx
      

  4.   

    1w记录并不多,虽然DataGrid的效率不好,但是也没到无法忍受的程度,问题还是在你的程序中
      

  5.   

    我发一个分页存储过程
    CREATE PROCEDURE select_CutPage
    @PageRecord int ,
    @currentPage int,
    @keyIdName varchar(200),
    @tableName varchar(500)
    AS
    Declare @stmt nvarchar(200),
            @ErrorSave int
    SET @ErrorSave =0
    set @stmt=N'Select top '+Cast(@PageRecord as char)+
            N' * from '+@tableName+N' where '+@keyIdName+' not in(select top '+
           Cast(@PageRecord*@currentPage as char)+@keyIdName+
            N' from '+@tableName+N' order by '+@keyIdName+N' asc)'
    exec sp_Executesql @stmt
    select @ErrorSave=@@ERROR
    Return @ErrorSave
    go
      

  6.   

    分页时应该是要显示哪些记录就从数据库中取哪几条出来.有1000页*10条记录,显示第2页就只取第11条~第20条.这里难点是存储过程:http://blog.csdn.net/yingcongxiao/archive/2006/03/08/618705.aspx--///////////////////////////////////////////////////////////////////////////////////////////////
    if exists (select * from  sysobjects where  id = object_id('GetRecordPageTotal')and type = 'P')
       drop procedure GetRecordPageTotal
    go
    if exists (select * from  sysobjects where  id = object_id('PgetRecordByPage')and type = 'P')
       drop procedure PgetRecordByPage
    go
    --///////////////////////////////////////////////////////////////////////////////////////////////
    create procedure GetRecordPageTotal
        @tblName      varchar(100),                         -- 表名   
      --  @PageSize     int,                            -- 页大小
        @strWhere     varchar(1000) = ''                    -- 查询条件 (注意: 不要加 where)
    as begin
     declare @strSqlTemp varchar(2000)                -- 临时变量 
      
     
     if @strWhere=''
      set @strSqlTemp='select count(*) from ['+@tblName+']'
     else set @strSqlTemp='select count(*) from ['+@tblName+'] where '+@strWhere
     
     exec (@strSqlTemp)
    endGO--////////////////////////////////////////////////////////////////////////////////////////////////
    create procedure GetRecordByPage
        @tblName      varchar(100),       -- 表名
        @fldCow   varchar(100)='*',   -- 要查询的列
        @fldName      varchar(255),       -- 排序列
        @PageSize     int = 10,           -- 页尺寸
        @PageIndex    int = 1,            -- 页码
        @OrderType    bit = 1,            -- 设置排序类型, 1则降序
        @strWhere     varchar(2000) = ''  -- 查询条件 (注意: 不要加 where)
    ASdeclare @strSQL   varchar(3000)       -- 主语句
    declare @strTmp   varchar(1000)       -- 临时变量
    declare @strOrder varchar(500)        -- 排序类型if @OrderType != 0
    begin
        set @strTmp = '<(select min'
        set @strOrder = ' order by [' + @fldName + '] desc'
    end
    else
    begin
        set @strTmp = '>(select max'
        set @strOrder = ' order by [' + @fldName + '] asc'
    endset @strSQL = 'select top ' + str(@PageSize) + ' '+@fldCow+' from ['
        + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
        + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
        + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
        + @strOrderif @strWhere != ''
        set @strSQL = 'select top ' + str(@PageSize) + ' '+@fldCow+ ' from ['
            + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
            + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
            + @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
            + @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrderif @PageIndex = 1
    begin
        set @strTmp = ''
        if @strWhere != ''
            set @strTmp = ' where (' + @strWhere + ') '    set @strSQL = 'select top ' + str(@PageSize) + ' '+@fldCow+ ' from ['
            + @tblName + ']' + @strTmp + ' ' + @strOrder
    endexec (@strSQL)
    GO
    注:不想分页的话,把PageSize 值设到int最大值就行了
      

  7.   

    其實有沒有人想到可能可以優化數據庫Table的設計呢?特別是注意index
    我試過一次200條記錄他給我用了3秒,我沒嚇死
      

  8.   

    对表查询条件字段加索引。
    核心sql语句是:如果有id主键,是自增的,pageno
    select top 10 from 表 where id > (select top '"+(pageno-1)*10+"' max(id) from 表 order by id)  order by id
    明白方法就好。
      

  9.   

    http://www.microsoft.com/china/community/Column/13.mspx