大数量查询分页显示

C# Linq查询、where 扩展查询以及QueryExpression分页查询 C# 常用的三种查询方式 阅读详情

微软的解决办法


using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;

public class PagingSample: Form
{
// Form controls.
Button prevBtn = new Button();
Button nextBtn = new Button();

static DataGrid myGrid = new DataGrid();
static Label pageLbl = new Label();

// Paging variables.
static int pageSize = 10; // Size of viewed page.
static int totalPages = 0; // Total pages.
static int currentPage = 0; // Current page.
static string firstVisibleCustomer = ""; // First customer on page to determine location for move previous.
static string lastVisibleCustomer = ""; // Last customer on page to determine location for move next.

// DataSet to bind to DataGrid.
static DataTable custTable;

// Initialize connection to database and DataAdapter.
static SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
static SqlDataAdapter custDA = new SqlDataAdapter("", nwindConn);
static SqlCommand selCmd = custDA.SelectCommand;

public static void GetData(string direction)
{
// Create SQL statement to return a page of records.
selCmd.Parameters.Clear();

switch (direction)
{
case "Next":
selCmd.CommandText = "SELECT TOP " + pageSize + " CustomerID, CompanyName FROM Customers " +
"WHERE CustomerID > @CustomerId ORDER BY CustomerID";
selCmd.Parameters.Add("@CustomerId", SqlDbType.VarChar, 5).Value = lastVisibleCustomer;
break;
case "Previous":
selCmd.CommandText = "SELECT TOP " + pageSize + " CustomerID, CompanyName FROM Customers " +
"WHERE CustomerID < @CustomerId ORDER BY CustomerID DESC";
selCmd.Parameters.Add("@CustomerId", SqlDbType.VarChar, 5).Value = firstVisibleCustomer;
break;
default:
selCmd.CommandText = "SELECT TOP " + pageSize + " CustomerID, CompanyName FROM Customers ORDER BY CustomerID";

// Determine total pages.
SqlCommand totCMD = new SqlCommand("SELECT Count(*) FROM Customers", nwindConn);
nwindConn.Open();
int totalRecords = (int)totCMD.ExecuteScalar();
nwindConn.Close();
totalPages = (int)Math.Ceiling((double)totalRecords / pageSize);

break;
}

// Fill a temporary table with query results.
DataTable tmpTable = new DataTable("Customers");
int recordsAffected = custDA.Fill(tmpTable);

// If table does not exist, create it.
if (custTable == null)
custTable = tmpTable.Clone();

// Refresh table if at least one record returned.
if (recordsAffected > 0)
{
switch (direction)
{
case "Next":
currentPage++;
break;
case "Previous":
currentPage--;
break;
default:
currentPage = 1;
break;
}

pageLbl.Text = "Page " + currentPage + " of " + totalPages;

// Clear rows and add new results.
custTable.Rows.Clear();

foreach (DataRow myRow in tmpTable.Rows)
custTable.ImportRow(myRow);

// Preserve first and last primary key values.
DataRow[] ordRows = custTable.Select("", "CustomerID ASC");
firstVisibleCustomer = ordRows[0][0].ToString();
lastVisibleCustomer = ordRows[custTable.Rows.Count - 1][0].ToString();
}
}



public PagingSample()
{
// Initialize controls and add to form.
this.ClientSize = new Size(360, 274);
this.Text = "NorthWind Data";

myGrid.Location = new Point(10,10);
myGrid.Size = new Size(340, 220);
myGrid.AllowSorting = true;
myGrid.CaptionText = "NorthWind Customers";
myGrid.ReadOnly = true;
myGrid.AllowNavigation = false;
myGrid.PreferredColumnWidth = 150;

prevBtn.Text = "<<";
prevBtn.Size = new Size(48, 24);
prevBtn.Location = new Point(92, 240);
prevBtn.Click += new EventHandler(Prev_OnClick);

nextBtn.Text = ">>";
nextBtn.Size = new Size(48, 24);
nextBtn.Location = new Point(160, 240);

pageLbl.Text = "No Records Returned.";
pageLbl.Size = new Size(130, 16);
pageLbl.Location = new Point(218, 244);

this.Controls.Add(myGrid);
this.Controls.Add(prevBtn);
this.Controls.Add(nextBtn);
this.Controls.Add(pageLbl);
nextBtn.Click += new EventHandler(Next_OnClick);


// Populate DataSet with first page of records and bind to grid.
GetData("Default");
DataView custDV = new DataView(custTable, "", "CustomerID", DataViewRowState.CurrentRows);
myGrid.SetDataBinding(custDV, "");
}



public static void Prev_OnClick(object sender, EventArgs args)
{
GetData("Previous");
}

public static void Next_OnClick(object sender, EventArgs args)
{
GetData("Next");
}
}



public class Sample
{
static void Main()
{
Application.Run(new PagingSample());
}
}

大数据量多线程执行分页查询 CREATE_TABLE.txt 是测试的数据表 立即下载

相关推荐

minist手写数字的识别代码复现(pytorch 版本)

电脑系统:Windows 10语言环境:Python 3.8.18编译器:jupyter notebook深度学习环境:torch == 1.13.1+cu116显卡及显存: Tesla V100-PCIE-32GB卷积神经网络(Convolutional Neural Network,CNN或ConvNet)是一种 具有局部连接、权重共享等特性的深层前馈神经网络. 目前的卷积神经网络一般是由卷积层、汇聚层和全连接层交叉堆叠而成的 前馈神经网络。

2202_75521293的博客 2620

ASP.NET大数据量查询分页例子

 如果是access 就用这个SQLHELPER http://hi.youkuaiyun.com/link.php?url=http://blog.youkuaiyun.com/zzxap 如果是MSSQL 就用这个sqlhelper http://www.cnblogs.com/zzxap/archive/2009/11/05/1596773.html前台 如果你用的是 gridview 就把Repeater替换

hxwangcong的专栏 1099

在Visual Studio中搭建Dynamo Python开发环境,效率飞一般的增长

在Visual Studio中搭建Dynamo Python开发环境,效率飞一般的增长

BIM的乐趣 1730

CRM QueryExpression的分页查询

#大于5000条数据分页查询QueryExpression 附上一个链接https://blog.youkuaiyun.com/y_f123/article/details/51307526 public static void QueryPage(IOrganizationService service, QueryExpression query, Action<EntityCollection...

Gao996的博客 3454

从M.2到E1.S,从U.2到E3.S:数据中心SSD接口的世代更迭与选择逻辑

本文深入探讨了数据中心SSD接口从M.2、U.2到E1.S、E3.S的演进历程与选型逻辑。通过对比分析不同接口的物理规格、性能表现和散热设计,揭示了EDSFF接口在数据中心环境中的优势,包括更高的部署密度、更好的散热效能和更强的扩展能力。文章还提供了针对不同应用场景的SSD选型建议,帮助IT决策者优化存储架构。

weixin_33816300的博客 417

如何编写 Skill 实现自动化用例生成

Skill 本质上是一组结构化的指令和工具定义,它告诉 AI 模型在特定场景下应该遵循什么流程、调用哪些工具、输出什么格式的内容。元信息:名称、描述、版本等。指令(Instructions):定义 AI 的行为准则和任务流程。工具(Tools):AI 可以调用的外部能力,如文件读写、代码执行、API 请求等。上下文(Context):预设的输入输出格式或示例。编写一个用于自动生成测试用例的 Skill,核心在于定义清晰的指令流程和输出规范。

Cesare的博客 2699

C# 对sql通用分页方法

DECLARE @indexTabel TABLE(Nid int IDENTITY(1,1) PRIMARY KEY,aId int) INSERT INTO @indexTabel  Select bc.Id From XX bc With(NOLOCK) Where 1=1 AND bc.DataFlag=1  and bc.CreateDate > ='2016-03-01'  

Haibing的博客 2745

【Rcode】生存分析: KM & COX回归& 随机森林& nomogram

本文使用了R——survival包下的lung数据进行方法测试: 1)KM 2) Cox回归:多因素 3)随机森林因子(根据cox回归结果) 4)nomogram ( 根据cox回归结果,建立了中位生存时间,1年5年生存率的概率计算) -------------------????????‍♀️本文只有干货,非常干!????----------------------------- 一、数据加载 #生存分析 library("survival") library("survminer") data("

weixin_43172152的博客 9273

java 分页总数_大数量查询分页显示

微软的解决办法usingSystem;usingSystem.Data;usingSyst运维微软的解决办法using System;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Windows.Forms;public class PagingSample: Form{// Form...

weixin_39604685的博客 816

大模型工作流Dify面试题及参考答案

设计一个基于 Dify 的智能摘要与重点提取 Agent,需结合Prompt 工程、模型能力配置和工作流优化,确保对长文本的高效解析和关键信息提炼。1. 明确任务需求与输入输出输入:长文本内容(如文章、报告、会议记录)或文本 URL输出摘要:简洁概括原文核心内容,控制在原文长度的 10%-20%重点列表:分点列出关键数据、结论、行动项等可选:关键词提取、情感倾向分析示例场景输入:一篇 5000 字的行业报告。

大模型大数据攻城狮的专栏 2513

【Halcon-2D测量】add_metrology_object_rectangle2_measure 函数功能(用于向2D计量模型中添加旋转矩形(rectangle2类型)计量对象)

HALCON算子add_metrology_object_rectangle2_measure解析摘要 该算子是HALCON 2D计量模块的核心算子,用于添加旋转矩形计量对象并配置测量参数。主要功能包括:定义旋转矩形几何轮廓(中心坐标、主轴角度、长短半长);生成垂直于矩形边界的测量区域;设置边缘提取预处理参数(高斯平滑、振幅阈值)。关键注意事项:MeasureLength1必须小于矩形长短半长;角度参数Phi需使用弧度单位;多线程需同步模型句柄。该算子适用于方形螺母、PCB板边框等矩形零件的精密测量,需与a

weixin_45590420的博客 1223

大数量查询分页显示 微软的解决办法

微软的解决办法usingSystem;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Windows.Forms;publicclassPagingSample:Form{//Formcontrols.ButtonprevBtn=newButton();ButtonnextBtn=new

sinodier的专栏 324

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

大数量查询分页显示 (From derny)

微软的解决办法using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms; public class PagingSample: Form { // Form controls. Button prevBtn = new Button

简单·爱 693

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

大数量查询分页显示微软的解决办法

<!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--><script type="text/javascript"

zgqtxwd的专栏 249

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

上一篇: oracle启动监听后10秒以后再连数据库就提示没有监听的原因
下一篇: 如何解决 SQL Server 2000 中的连接问题
derny
博客等级 码龄23年 16粉丝 189原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值