• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP > 大数量查询分页显示 微软的解决办法

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

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了工程数量管理办法,工程数量控制办法,微软黑屏解决办法,北京联合办公数量,sci论文数量统计等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
微软的解决办法
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&q
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

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

相关文章

  • 2017-05-11雷客图ASP站长安全助手的ASP木马查找功能
  • 2017-05-11ASP经典分页类
  • 2017-05-11asp中rs.BookMark的使用介绍
  • 2017-05-11asp制作中常用到的函数库集合第1/8页
  • 2017-05-11最小asp后门程序
  • 2017-05-11用cookies实现闪电登录论坛方法
  • 2017-05-11asp实现本周的一周时间列表的代码
  • 2017-05-11asp 用InStr查找特定字符串的代码
  • 2017-05-11非常好用的asp备份,还原SQL数据库的代码
  • 2017-05-11一个改进的ASP生成SQL命令字符串类的代码[已测]

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 解决rs.absolutepage=-1的问题
    • asp实现树型结构
    • ASP网页模板的应用: 让程序和界面分离,让ASP脚本更清晰,更换界面更容易
    • 独立图片服务器的图片上传的解决方式
    • asp下为什么韩文字后面显示分号?
    • 读取目录下的文件得到一个数组
    • asp之自动闭合HTML/ubb标签函数 附简单注释
    • 构建免受 FSO 威胁虚拟主机(二)
    • 结合asp和存储过程做的搜索程序
    • 改进 ASP 的字符串处理性能

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有