日期:2014-05-18  浏览次数:20837 次

存储过程返回值问题
为什么获取不到返回值
而在存储过程里可以获取返回信息

string sql = "sp_PageView";
string PageSum = "1";
string NextPage = "?tyid=" + Request.QueryString["tyid"] + "&page=";
string MMsql = " Fn_suo=0 and Fn_del=0 and Fn_lang=0 and Fn_typeidd=1 ";
int MM_sum = 6;
if (GoPage + "a" != "a")
{
PageSum = GoPage;//得到传递页数
}
if (Request.QueryString["tyid"] + "a" != "a")
{
MMsql += " and Fn_typeid=" + Convert.ToInt32(Request.QueryString["tyid"]) + "";
}
SqlParameter[] param = new SqlParameter[9];
param[0] = new SqlParameter("@tbname", " Fan_news ");
param[1] = new SqlParameter("@FieldKey", " Fn_id ");
param[2] = new SqlParameter("@PageCurrent", Convert.ToInt32(PageSum));
param[3] = new SqlParameter("@PageSize", MM_sum);
param[4] = new SqlParameter("@FieldShow", "");
param[5] = new SqlParameter("@FieldOrder", " Fn_xu desc, Fn_id desc ");
param[6] = new SqlParameter("@Where", MMsql);
param[7] = new SqlParameter("@PageCount", SqlDbType.Int, 4);
param[7].Direction = ParameterDirection.Output;
param[8] = new SqlParameter("@Allcount", SqlDbType.Int, 4);
param[8].Direction = ParameterDirection.Output;
DataSet Guest_Ds = SqlHelper.ExecuteTable(CommandType.StoredProcedure, sql, param);
int MM_page_count = Convert.ToInt32(param[7].Value); //返回存储过程值(总页数)
int MM_page_total = Convert.ToInt32(param[8].Value);//返回存储过程值(总项数)
PagedDataSource Guest_Pds = new PagedDataSource();
Guest_Pds.DataSource = Guest_Ds.Tables[0].DefaultView;
Guest_Pds.AllowPaging = false;//允许翻页
Guest_Pds.PageSize = MM_sum;//每页显示数量
MM_page_total = Convert.ToInt32(Guest_Pds.DataSourceCount.ToString());//得到总条数
Guest_Pds.CurrentPageIndex = Convert.ToInt32(PageSum) - 1;//得到当前页数
Repeater1.DataSource = Guest_Pds;//指定数据源名称
PageSum = (Guest_Pds.CurrentPageIndex + 1).ToString();//得到当前页数
page mp = new page();

Label1.Text = mp.MyPage_number_two(NextPage, PageSum, Convert.ToInt32(MM_page_count), Convert.ToInt32(MM_page_total));
Repeater1.DataBind();

/////////////////////////////////////////////////////////////////////////////////////////////////////////
create PROC sp_PageView
@tbname sysname, --要分页显示的表名
@FieldKey nvarchar(1000), --用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段
@PageCurrent int=1, --要显示的页码
@PageSize int=10, --每页的大小(记录数)
@FieldShow nvarchar(1000)='', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段
@FieldOrder nvarchar(1000)='', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC用于指定排序顺序
@Where nvarchar(1000)='', --查询条件
@PageCount int OUTPUT , --总页数
@Allcount int output ---总项数
AS
SET NOCOUNT ON
--检查对象是否有效
IF OBJECT_ID(@tbname) IS NULL
BEGIN
 RAISERROR(N'对象"%s"不存在',1,16,@tbname)
 RETURN
END
IF OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTable')=0
 AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsView')=0
 AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTableFunction')=0
BEGIN
 RAISERROR(N'"%s"不是表、视图或者表值函数',1,16,@tbname)
 RETURN
END

--分页字段检查
IF ISNULL(@FieldKey,N'')=''
BEGIN
 RAISERROR(N'分页处理需要主键(或者惟一键)',1,16)
 RETURN
END

--其他参数检查及规范
IF ISNULL(@PageCurr