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

分页|解决|微软|显示|分页|微软

微软的解决办法
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(

时间: 2024-08-30 13:16:36

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

大数量查询分页显示 微软的解决办法_应用技巧

微软的解决办法 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

struts2.0-只用Struts2框架多条件查询分页显示dao接口该咋写

问题描述 只用Struts2框架多条件查询分页显示dao接口该咋写 只用struts2框架不用hibernate和spring,可以多条件查询并且分页显示,要求一进去界面就显示查询结果那样子,dao接口该怎么写呢,实现类怎么写.sql语句往哪放啊.大神,求解啊. 解决方案 那你用什么与数据库交互?jdbc? 解决方案二: 实体类里创建个list',然后遍历list,应该是用jdbc 解决方案三: 实体类里创建个list',然后遍历list,应该是用jdbc

小程序构成大项目之——分页显示

程序|分页|显示|项目 小程序构成大项目之--分页显示 陈根发 好久没有写文章了,就是觉得有点对不起自己,看我文章的人大概不多,所以就无所谓对不对的起大家了.:) 笔者最近刚刚走出校门,满脑子混杂的东西,没有心事静下来写东西,今天有空,不错,写点. 我每次写的东西都有点班门弄斧的味道,但是抑制不住自己的想写的欲望.如果有碍视线,请各位见谅. 不过笔者最主要的意思还是希望大家通过这些只字片段认识我这个人.在人生的职业生涯中,技术也许是中坚力量,但是人生的整个旅途中,也许还有其他的东西比技术更重要!

SSRS (SQL Server Report Service) 在IE9, IE10下显示不全的解决办法

原文:SSRS (SQL Server Report Service) 在IE9, IE10下显示不全的解决办法 在做项目的过程中遇到SSRS与IE9, IE10不兼容的情况,具体表现为报表页面在IE9 和 IE10下面只显示三分之一,靠左显示,下方有滚动条,右三分之二为空白.查看源代码后发现,上面一个<tr>里只有一个<td>,并colspan=3, 下面报表内容区域的<tr>有三个<td>但前两个是hidden的.最初是想把表格结构调整下,去掉前面hid

jquery fancybox ie6不显示关闭按钮的解决办法

 本篇文章主要是对jquery fancybox ie6不显示关闭按钮的解决办法进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 解决办法:   打开jquery.fancybox-1.3.4.css 注释掉这行就行了: 代码如下: .fancybox-ie6 #fancybox-close    {       background: transparent;       filter: progid:DXImageTransform.Microsoft.AlphaImageLoade

暴风影音播放自带字幕的视频却无法显示字幕的解决办法

  暴风影音播放自带字幕的视频却无法显示字幕的解决办法          1.打开设备管理器(可以通过右击计算机--属性--设备管理器来打开); 2.可以根据显卡配置到官网升级显卡驱动(最稳妥方法),或者通过驱动精灵等软件进行检测,再升级显卡驱即可.

BootStrap 图标icon符号图标glyphicons不正常显示的快速解决办法_javascript技巧

 bootstrap 图标icon符号图标glyphicons不正常显示解决办法如下所示: 分享供各位参考: 1.在ff/http:的地址栏中输入"about:config",即进入配置界面. 2.进入后,搜索"security.fileuri.strict_origin_policy",这是该值应该是true. 3.双击该项,其值自动变为false,即可. 4.修改后,再刷新遇到问题的页面,即可看到正常显示的图标了. 探究问题原因: 1.由于ff/http:一个安

有关easyui-layout中的收缩层无法显示标题的解决办法_jquery

easyui-layout中的收缩层无法显示标题的问题原因分析: 在easyui-layout中设置面板初始化为可以折叠,然后就发现标题还有图标都木有了 嗯,就是结果列表上面.一片空白,出现了问题就要去解决它,在网上查了资料之后呢,决定修改jquery.easyui.min.js 版本为:jQuery EasyUI 1.4.1 在5105行有_39d方法,在其中设置两个变量_Cstitle,_CsIcon添加代码如下: var _Cstitle; var _closedTitle = p.pan

jQuery fancybox在ie浏览器下无法显示关闭按钮的解决办法_jquery

 如果版本是: 1.3.1 IE无法显示关闭按钮 如果版本是: 1.3.4 IE6无法显示关闭按钮 解决办法: Version: 1.3.1 打开fancybox.css 注释掉此行: .fancybox-ie #fancybox-close { background: transparent; filter: progid : DXImageTransform.Microsoft.AlphaImageLoader ( src = 'images/fancy_close.png', sizing