简单分页

zhoudan3986226 2009-01-18 04:51:18
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.Common;
using System.Data.OleDb;

public partial class Array : System.Web.UI.Page
{
int allcount;//所有页数
int pagesize;//每页数据书
int allpage;//所有页数
int pageid;//当前页数
int page;
protected void Page_Load(object sender, EventArgs e)
{
pageidLabel.Text = Convert.ToString(pageid);
allpageLabel.Text = Convert.ToString(allpage);
if (pageid == allpage)
nextLinkButton2.Enabled = false;
if (page == 1)
upLinkButton3.Enabled = false;

}
//分页函数
protected void pagedis()
{
StringBuilder strHTML = new StringBuilder();
if (allcount > 0)
{
allpage = allcount / pagesize;
if (allcount % pagesize != 0)
allpage++;
pageid = Convert.ToInt32(Request.QueryString["page"]);
if (pageid <= 1)
pageid = 1;
if (pageid > 1)
pageid = Convert.ToInt32(Request.QueryString["page"]);
if (pageid >= allpage)
pageid = allpage;

int nstart = pagesize * (pageid - 1);
int nend = nstart + (pagesize - 1);
//if(nend>allcount-1)


}
Response.Write(strHTML);
}

public void datadb(string sql)
{
try
{
string db = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/db.mdb");
DbProviderFactory dbfactory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection dbcon = dbfactory.CreateConnection();
dbcon.ConnectionString = db;
dbcon.Open();
DbCommand dbcom = dbfactory.CreateCommand();
dbcom.Connection = dbcon;
dbcom.CommandText = "select ID,Subject,KindCode from tableTest Order by ID DESE";
DbDataAdapter adapter =new DbDataAdapter();
adapter.SelectCommand=dbcom;
DataSet ds = new DataSet();
adapter.Fill(ds, "pg");
DataTable tb = new DataTable();
tb = ds.Tables[0];
dbcon.Close();
dbcon.Dispose();
pageList1.DataSource = ds.Tables[0];
pageList1.DataBind();
allcount = tb.Rows.Count;
}
catch (Exception ms)
{
Response.Write(ms.Message);
}
}

protected void firstLinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Array.aspx?page=1");
}
protected void nextLinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Array.aspx.?page=" +Convert.ToInt32(pageid - 1)+ "");
}
protected void upLinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("Array.aspx?page=" + Convert.ToInt32(pageid + 1)+ "");
}
protected void lastLinkButton4_Click(object sender, EventArgs e)
{
Response.Redirect("Array.aspx?page=" + allpage + "");
}
}
错误 1 无法创建抽象类或接口“System.Data.Common.DbDataAdapter”的实例 F:\check\Array.aspx.cs 70 36 F:\check\
高手帮该下
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
swalp 2009-01-19
  • 打赏
  • 举报
回复
up
huanxiangsugars 2009-01-18
  • 打赏
  • 举报
回复
UP
Blade7 2009-01-18
  • 打赏
  • 举报
回复
分页居然用 LinkButton,然后再 Response.Redirect?——这简直是最差的做法了,楼主应该直接用链接啊
muyebo 2009-01-18
  • 打赏
  • 举报
回复
DbDataAdapter的类应该是个抽象类,不能被实例化的
muyebo 2009-01-18
  • 打赏
  • 举报
回复


DbDataAdapter adapter;//不要new了试试
adapter.SelectCommand=dbcom;
DataSet ds = new DataSet();
adapter.Fill(ds, "pg");
DataTable tb = new DataTable();
tb = ds.Tables[0];

gonghuaqiao 2009-01-18
  • 打赏
  • 举报
回复
DbDataAdapter adapter =new DbDataAdapter();
adapter.SelectCommand=dbcom;
>>
DbDataAdapter adapter =new DbDataAdapter(dbcom);
试试

zhoudan3986226 2009-01-18
  • 打赏
  • 举报
回复
DbDataAdapter adapter =new DbDataAdapter(); 实例化的时候报错

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧