c# - 如何在 C# 中延迟加载 DataGridView

标签 c# sql sql-server lazy-loading

我想从 sql server 中检索大数据。我希望它逐行加载并显示到 DataGridView 中。就像我在 Sql server management studio 2005 中执行 Sql Script 一样。我该怎么做?!

最佳答案

使用此查询进行分页

DECLARE @PageIndex int=1
DECLARE @PageSize int=10
DECLARE @StartRow int
DECLARE @EndRow int


SET @StartRow = (@PageSize * (@PageIndex - 1))  + 1  
SET @EndRow = @PageSize * @PageIndex + 1

SET NOCOUNT ON;

WITH ArticleSearch AS
(
    SELECT
       ROW_NUMBER() OVER 
         (
            -- Dynamic sorting
            ORDER BY       tablename.fieldname 


          ) AS RowNumber,   *


     FROM            tablename

)

-- Statement that executes the CTE
SELECT *
FROM
      ArticleSearch a
WHERE
      a.RowNumber BETWEEN @StartRow AND @EndRow - 1
ORDER BY
      a.RowNumber 

您可以将 pageindex 作为参数传递,以获取要显示的页面和每个页面中总记录的 pagesize

关于c# - 如何在 C# 中延迟加载 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576010/

相关文章:

c# - 线程结束时在主线程上回调

sql - 如何返回数据库中所有表的变量​​的不同计数?

sql - 我可以试运行/沙盒 sql 命令吗?

sql-server - 为什么使用条件情况时会得到 int 数据类型?

sql - 无法连接到 SQL Server 数据库

c# - 如何从非常大的列表中按索引有效地删除元素?

c# - 使用 .NET Core 应用程序优雅地处理 AWS ECS 停止任务

c# - Windows Azure 项目 Web 角色入口点主机已停止错误

java - mysql - 选择查询输出文件 - 文件保存在哪里

php - Mysql比较日期时间