.net连续刷新报错~!~
错误
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: 未指定的错误
Source Error:
Line 71: OleDbConnection myconnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + HttpContext.Current.Server.MapPath(@"~/App_Data/kh1454578s.mdb"));
Line 72: OleDbCommand addCommand = new OleDbCommand(strCount, myconnection);
Line 73: addCommand.Connection.Open();
Line 74: OleDbDataReader dr;
Line 75: dr = addCommand.ExecuteReader(CommandBehavior.CloseConnection);
Source File: d:\2008\yunshengtang.com.cn\Product.aspx.cs Line: 73
Stack Trace:
[OleDbException (0x80004005): 未指定的错误]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1054881
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.OleDb.OleDbConnection.Open() +37
Product.CalculateRecord() in d:\2008\yunshengtang.com.cn\Product.aspx.cs:73
Product.Page_Load(Object sender, EventArgs e) in d:\2008\yunshengtang.com.cn\Product.aspx.cs:38
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
我代码
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 Product : System.Web.UI.Page
{
int CurrentPage;
int PageSize;
int PageCount;
int RecordCount;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PageSize = 6;
string sql;
if (Request.QueryString["type"] == null)
{
sql = "select * FROM [product]";
}
else
{
sql = "select * FROM [product] where type='" + Request.QueryString["type"] + "'";
}
if (!Page.IsPostBack)
{
//计算总共有多少记录
RecordCount = CalculateRecord();
//计算总共有多少页
//取整
PageCount = RecordCount / PageSize;
if (RecordCount % PageSize > 0)
PageCount = PageCount + 1;
lblPageCount.Text = PageCount.ToString();
lblRecordCount.Text = RecordCount.ToString();
ViewState["PageCount"] = PageCount;
CurrentPage = 0;
ViewState["PageIndex"] = 0;
//绑定
ListBind();
}
}
}
public string strCount;
public int CalculateRecord()
{
int intCount;
int bianlang1 = System.Convert.ToInt32(Request.QueryString["id"]);
if (Request.QueryString["type"] == null)
{
strCount = "select count(*) as co from [product]";
}
else
{
strCount = "select count(*) as co from [product] where type='" + Request.QueryString["type"] + "'";
}
OleDbConnection myconnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + HttpContext.Current.Server.MapPath(@"~/App_Data/kh1454578s.mdb"));
OleDbCommand addCommand = new OleDbCommand(strCount, myconnection);
addCommand.Connection.Open();
OleDbDataReader dr;
dr = addCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
addCommand.Connection.Close();
myconnection.Close();
}
public string strSel;
ICollection CreateSource()
{
int bianlang1 = System.Convert.ToInt32(Request.QueryString["id"]);
int StartIndex;
//设定导入的起终地址
StartIndex = CurrentPage * PageSize;
if (Request.QueryString["type"] == null)
{
strSel = "select * from [product]";
}
else
{
strSel = "select * from [product] where type='" + Request.QueryString["type"] + "'";
}
OleDbConnection myconnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + HttpContext.Current.Server.MapPath(@"~/App_Data/kh1454578s.mdb"));
myconnection.Open();
DataSet ds = new DataSet();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel, myconnection);
MyAdapter.Fill(ds, StartIndex, PageSize, "products");
return ds.Tables["products"].DefaultView;
myconnection.Close();
}
public void ListBind()
{
DtProList.DataSource = CreateSource();
DtProList.DataBind();
DtProList.RepeatColumns = 3;
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
if (PageCount == 0)
{
lblCurrentPage.Text = "0";
lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = false;
}
else
{
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
}
public void Page_OnClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"];
string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
case "first":
CurrentPage = 0;
break;
case "last":
CurrentPage = PageCount - 1;
break;
}
ViewState["PageIndex"] = CurrentPage;
ListBind();
}
}