asp.net

yllee110 2012-06-12 09:01:13
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.Data.OleDb;

public partial class 留言板: System.Web.UI.Page
{




OleDbConnection conn = default(OleDbConnection);
int PageSize = 0;
int StartPosition = 0;
int CurrentPage = 0;
int TotalPage = 0;

public void Page_Load(object Sender, EventArgs E)
{
string conn = "Data Source=d:\\guest.mdb;Provider=Microsoft.Jet.OLEDB.4.0";
OleDbConnection myconn = new OleDbConnection(conn);




string connstring = System.Configuration.ConfigurationManager.AppSettings["connStr"];


if (!Page.IsPostBack)
{

BindData();
}
}

public void BindData()
{



TotalPage = Convert.ToInt32(GetTotalPage());


if (!string.IsNullOrEmpty(Request.QueryString["commandname"]))
{

switch (Request.QueryString["commandname"]) {
case "first":
CurrentPage = 1;
break;
case "prev":
CurrentPage = Convert.ToInt32(Session["CurrentPage"]) - 1;


if (CurrentPage < 1)
CurrentPage = 1;

break;
case "next":
CurrentPage = Convert.ToInt32(Session["CurrentPage"]) + 1;


if (CurrentPage > TotalPage)
CurrentPage = TotalPage;
break;
case "last":
CurrentPage = TotalPage;
break;
}

Session["CurrentPage"] = CurrentPage;
} else if ((Session["CurrentPage"] != null)) {

CurrentPage = Convert.ToInt32(Session["CurrentPage"]);
} else {

CurrentPage = 1;
Session["CurrentPage"] = CurrentPage;
}


OleDbDataAdapter adp = new OleDbDataAdapter("select * from guestorder by submit_date Desc", conn);


DataSet ds = new DataSet();



StartPosition = (CurrentPage - 1) * PageSize;


adp.Fill(ds, StartPosition, PageSize, "guest");

MyRepeater.DataSource = ds.Tables["guest"].DefaultView;
MyRepeater.DataBind();


theCurrentPage.Text = CurrentPage.ToString();
theTotalPage.Text = TotalPage.ToString();
}
public object GetTotalPage()
{
object functionReturnValue = null;

int TotalRecord = 0;
string db = Server.MapPath("guest.mdb");
string ConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
OleDbConnection myConn = new OleDbConnection(ConnectionStr);
myConn.Open();
string strsql = "select count(*) as total From guest";
OleDbCommand cmd = new OleDbCommand(strsql, myConn);

OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read()) {
// intCount = Int32.Parse(dr.Item("total").ToString)
TotalRecord = Convert.ToInt32(dr["total"]);
} else {
TotalRecord = 0;
}
myConn.Close();

if ((TotalRecord % PageSize) == 0)
{

functionReturnValue = TotalRecord / PageSize;
}
else
{

functionReturnValue = TotalRecord / PageSize + 1;
}
return functionReturnValue;
}
public void tijiao_Click(object Sender, EventArgs E)
{


OleDbConnection conn = new OleDbConnection
("Data Source=d:\\guest.mdb;Provider=Microsoft.Jet.OLEDB.4.0");





string strA = null;
string strB = null;
string strSql = null;
strA = "Insert Into guest(title,name,submit_date";
strB = " Values('" + title.Text + "','" + name.Text + "',#" + DateTime.Now + "#";


if (!string.IsNullOrEmpty(body.Text)) {
strA = strA + ",body";
strB = strB + ",'" + (body.Text) + "'";
}
strSql = strA + ")" + strB + ")";
OleDbCommand cmd = new OleDbCommand(strSql, conn);
Exception Exp = null;
try {

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

BindData();
} catch {

BindData();
}


title.Text = "";
body.Text = "";
name.Text = "";
email.Text = "";


}


}



异常详细信息: System.DivideByZeroException: 试图除以零。

源错误:


行 127: myConn.Close();
行 128:
行 129: if ((TotalRecord % PageSize) == 0)
行 130: {
行 131:

源文件: d:\asp1\留言板.aspx.cs 行: 129

堆栈跟踪:


[DivideByZeroException: 试图除以零。]
留言板.GetTotalPage() in d:\asp1\留言板.aspx.cs:129
留言板.BindData() in d:\asp1\留言板.aspx.cs:48
留言板.Page_Load(Object Sender, EventArgs E) in d:\asp1\留言板.aspx.cs:39
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3743



请大家帮帮忙,谢谢。
...全文
86 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2012-06-12
  • 打赏
  • 举报
回复
分页看看aqspnetpager分页控件
if(PageSize>0)
{
}
zytp 2012-06-12
  • 打赏
  • 举报
回复
PageSize 不能为0

你设置一下不为0就行了
风一样的大叔 2012-06-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

PageSize 不能为0

你设置一下不为0就行了
[/Quote]
  • 打赏
  • 举报
回复
一致认为 PageSize = 0
gzw13999 2012-06-12
  • 打赏
  • 举报
回复
PageSize 值错误。。

加个默认值啊。
lyc120 2012-06-12
  • 打赏
  • 举报
回复
OleDbConnection conn = default(OleDbConnection);
int PageSize = 0;

先PageSize=20看看

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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