RecordCount = Convert.ToInt32(cmd.ExecuteScalar()); 这句出现问题,怎么改呢?

usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS... 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.SqlClient;public partial class lyb : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Session["admin"] != null) { admin_go.Text = "退出管理"; admin_go.NavigateUrl = "exit.aspx"; } if (!this.IsPostBack) { string ToPage = Request.QueryString["ToPage"]; if (ToPage == null) { ToPage = "1"; } if (!StrRegExp.IsID(ToPage)) { ToPage = "1"; } this.Bind_rptList(Convert.ToInt32(ToPage)); } } private void Bind_rptList(int ToPage) { int CurrentPage = ToPage; int PageSize = 5; int PageCount; int RecordCount; string PageSQL; string DataTable = "book"; string DataFiled = "ID"; string DataFileds = "ID,UserName,Face,Sex,QQ,HomePage,Email,IsHidden,Adddate,body,isrely,rebody"; string DataOrders = "ID Desc"; SqlConnection Conn = DB.createdb(); // string connstring = ConfigurationManager.AppSettings["cn"]; // SqlConnection Conn = new SqlConnection(); // Conn.ConnectionString = connstring; // conn.Open(); Conn.Open(); //* 取得记录总数,计算总页数 SqlCommand cmd = new SqlCommand("Select Count(" + DataFiled + ") From " + DataTable, Conn);
if ((RecordCount % PageSize) != 0) { PageCount = RecordCount / PageSize + 1; } else { PageCount = RecordCount / PageSize; } if (ToPage > PageCount) { CurrentPage = PageCount; } if (CurrentPage <= 1) { PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Order By " + DataOrders; } else { PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Where " + DataFiled + " Not In ( Select Top " + PageSize * (CurrentPage - 1) + " " + DataFiled + " From " + DataTable + " Order By " + DataOrders + " ) Order By " + DataOrders; } 后面的串码我就省略了。。。
展开
 我来答
Dong_Black
2013-04-26
知道答主
回答量:19
采纳率:0%
帮助的人:18.9万
展开全部
数据库连接未打开呗,每次操作之前进行Open方法,操作完成Close
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式