用存储过程进行分页时,取输入参数始终为空串。代码如下:
// 取数据集方法,并返回pageCount(总页数)
public DataSet getResult(string currentPage, ref string pageCount)
{
try
{
//清空数据集
ds.Clear();
string sql = "pageHandler";
//打开连接
OpenConnection();
cmd = new SqlCommand(sql,conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@pageSize", SqlDbType.Int).Value = 5;
cmd.Parameters.Add("@currentPage", SqlDbType.Int).Value = int.Parse(currentPage);
cmd.Parameters.Add("@pageCount", SqlDbType.Int);
cmd.Parameters["@pageCount"].Direction = ParameterDirection.Output;
sda = new SqlDataAdapter(cmd);
pageCount = cmd.Parameters["@pageCount"].Value.ToString();
sda.Fill(ds);
}
catch (Exception)
{
throw;
}
finally
{
CloseConnection();
} return ds; }
调用方法如下:
protected void BindData()
{
string pageCount = "";
DataAccess.Class1 dc = new DataAccess.Class1();
DataSet ds = dc.getResult(ViewState["currentPage"].ToString(), ref pageCount); ViewState["pageCount"] = pageCount;
lbCurrentPage.Text = ViewState["currentPage"].ToString();
lbPageCount.Text = ViewState["pageCount"].ToString();
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
} 取出来的pageCount始终为初始值,经过调试,发现运行到 pageCount = cmd.Parameters["@pageCount"].Value.ToString();这条语句时就已经把空值赋值了.....存储过程在sqlserver2008里面调试没问题,能正确返回pageCount,各位帮忙下
// 取数据集方法,并返回pageCount(总页数)
public DataSet getResult(string currentPage, ref string pageCount)
{
try
{
//清空数据集
ds.Clear();
string sql = "pageHandler";
//打开连接
OpenConnection();
cmd = new SqlCommand(sql,conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@pageSize", SqlDbType.Int).Value = 5;
cmd.Parameters.Add("@currentPage", SqlDbType.Int).Value = int.Parse(currentPage);
cmd.Parameters.Add("@pageCount", SqlDbType.Int);
cmd.Parameters["@pageCount"].Direction = ParameterDirection.Output;
sda = new SqlDataAdapter(cmd);
pageCount = cmd.Parameters["@pageCount"].Value.ToString();
sda.Fill(ds);
}
catch (Exception)
{
throw;
}
finally
{
CloseConnection();
} return ds; }
调用方法如下:
protected void BindData()
{
string pageCount = "";
DataAccess.Class1 dc = new DataAccess.Class1();
DataSet ds = dc.getResult(ViewState["currentPage"].ToString(), ref pageCount); ViewState["pageCount"] = pageCount;
lbCurrentPage.Text = ViewState["currentPage"].ToString();
lbPageCount.Text = ViewState["pageCount"].ToString();
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
} 取出来的pageCount始终为初始值,经过调试,发现运行到 pageCount = cmd.Parameters["@pageCount"].Value.ToString();这条语句时就已经把空值赋值了.....存储过程在sqlserver2008里面调试没问题,能正确返回pageCount,各位帮忙下
解决方案 »
- FreetextBox的怪异问题!
- 获取GridView的图片URL
- 求.net 2.0空间
- 请问各位一个常碰见的的问题,怎样设置时间的样式????
- 急!!在线等!请各位大侠帮帮忙!我已经建立好了虚拟目录并且把.aspx文件设为了启始页在执行不调试时显示如下错误:“/SimpleControlDataBind
- 如何在datalist中为datagrid绑定数据
- 抢先简单地体验了一把“Visual Web Developer 2005 速成版的测试版 2”
- 高手们帮我研究一下这个存储过程通用调用类(C#)好吗?
- LINQ用户的ID存入Session中改怎么写
- 数据库中插入一个datetime时出错,搞不懂是为什么。。。
- 麻烦高手们看看,救救命~
- 凡客上的衣服颜色是怎么设计做到的
“pageCount = cmd.Parameters["@pageCount"].Value.ToString();”
先分别获取,
string s1=cmd.Parameters["@pageCount"].Value.ToString();//你说这个有值?走断点跟踪下。
pageCount=s1;//
string s2=pageCount;//看看有值没