存储过程的位置:
http://www.cnblogs.com/hertcloud/archive/2005/12/21/301327.html我的代码:
SqlConnection cnn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand _comm = new SqlCommand("proc_ListPageInt",cnn);
_comm.CommandType = CommandType.StoredProcedure;
SqlDataReader dr=null;
_comm.Parameters.Add("@tblName", SqlDbType.NVarChar, 200);
_comm.Parameters["@tblName"].Value = " info_public ";
_comm.Parameters.Add("@fldName", SqlDbType.NVarChar, 500);
_comm.Parameters["@fldName"].Value = " * ";
_comm.Parameters.Add("@pageSize", SqlDbType.Int);
_comm.Parameters["@pageSize"].Value = 5;
_comm.Parameters.Add("@page", SqlDbType.Int);
_comm.Parameters["@page"].Value = 1;
_comm.Parameters.Add("@fldSort", SqlDbType.NVarChar, 200);
_comm.Parameters["@fldSort"].Value = " infoid  ";
_comm.Parameters.Add("@Sort", SqlDbType.Bit);
_comm.Parameters["@Sort"].Value = true;
_comm.Parameters.Add("@strCondition", SqlDbType.NVarChar, 1000);
_comm.Parameters["@strCondition"].Value ="  ";
_comm.Parameters.Add("@ID", SqlDbType.NVarChar, 150);
_comm.Parameters["@ID"].Value = " infoid ";
_comm.Parameters.Add("@Counts", SqlDbType.Int, 0);
_comm.Parameters["@Counts"].Direction = ParameterDirection.Output;
_comm.Parameters.Add("@pageCount", SqlDbType.Int, 0);
_comm.Parameters["@pageCount"].Direction = ParameterDirection.Output;
cnn.Open();
dr=_comm.ExecuteReader();
//dr.Read();//有没有都一样去不到值!
string gdds="ff";
gdds=(string)_comm.Parameters["@Counts"].Value;
Response.Write(gdds);//网页上没有任何东西输出!dr 有值,而out int counts,out int pageCounts 取不到值 就80分了,全部给了!~

解决方案 »

  1.   

    把分全部分了,新开贴
    http://community.csdn.net/Expert/topic/5269/5269439.xml?temp=.632168
      

  2.   

    在事件探查器里看到,运行了此存储过程,并得到了结果!事件探查器:
    declare @P1 int
    set @P1=19
    declare @P2 int
    set @P2=4
    exec proc_ListPageInt @tblName = N' info_public ', @fldName = N' * ', @pageSize = 5, @page = 1, @fldSort = N' infoid  ', @Sort = 1, @strCondition = N'  ', @ID = N' infoid ', @Counts = @P1 output, @pageCount = @P2 output
    select @P1, @P2------------------------------------------
    结果:
        表1:
    ID    Title    ...
    ----------------------------------------
    1    kkkkkkk  ....
    ..
    ..  表2:
    无名列      无名列
    ------------------------------------
      19          4”无名列“就是输出参数的值!
      

  3.   

    不能用ExecuteReader用ExecuteNonQuery才可以但是这样执行两次 好麻烦(执行ExecuteNonQuery 返回输出参数值,执行ExecuteReader,返回SqlDataReader )所以我不用输出参数 而是获取一个dataset,
    在这个dataset里有两个表 一个是你要输出的参数值
    一个是查询的记录  可以根据需要返回 好多表
    比如:存储过程里有语句:
    select 'aaa'
    select 'bbb'
    dataset里有两个表  分别存放了 记录'aaa' 和'bbb'
      

  4.   

    ExecuteNonQuery,也用过,一样没有结果
      

  5.   

    可以使用ExecuteReader ,不能正确返回输出参数,是因为数据读取器没有关闭就去获取输出参数。建议在DataReader 读至数据末尾关闭后再进行输出。