create  proc RidSel
@single char(10) output,
@double char(10) output,
@business char(10) output,
@president char(10) output
--以上输出参数
as
select @single=Rid from rinfo where Rin='0'and Rtype='标准单人间'
select @double=Rid from rinfo where Rin='0'and Rtype='标准双人间'
select @business=Rid from rinfo where Rin='0'and Rtype='商务套房'
select @president=Rid from rinfo where Rin='0'and Rtype='总统套房'
GO
            SqlCommand cmd = new SqlCommand("RidSel", con);
            cmd.CommandType = CommandType.StoredProcedure;
            //
            SqlParameter single = new SqlParameter("@single",SqlDbType.Char,10);
            SqlParameter doub = new SqlParameter("@double", SqlDbType.Char, 10);
            SqlParameter business = new SqlParameter("@business", SqlDbType.Char, 10);
            SqlParameter president = new SqlParameter("@president", SqlDbType.Char, 10);
            single.Direction = ParameterDirection.Output;
            doub.Direction = ParameterDirection.Output;
            business.Direction = ParameterDirection.Output;
            president.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(single);
            cmd.Parameters.Add(doub);
            cmd.Parameters.Add(business);
            cmd.Parameters.Add(president);
            cmd.ExecuteNonQuery();
            //接下来如何读取存储过程里的返回的多个值?例如‘标准单人间’有4个,我只知道用single.value.ToString()只能读取其中的一个房间号,如何把4个房间号都显示出来?

解决方案 »

  1.   

    不要用输出参数,直接返回查询结果,用DataTable获取
      

  2.   

    DataSet ds = new DataSet();    
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = cmd;
    adapter.Fill(ds);
    foreach (var i in ds.Tables[0].Rows)
    {
        MessaageBox.Show(i[0]);
      

  3.   

    如果你想用输出参数的话那就把sql语句改一下,改成select @single=@single+','+Rid from rinfo where Rin='0'and Rtype='标准单人间',这样做的话参数字符长度要设置大点
      

  4.   

    如果是用ds.Tables[0].Rows提示“无法找到表 0”,如果是用ds.Tables["single"].Rows则提示未将对象引用设置到对象的实例
      

  5.   


    create  proc RidSel
    as
    select Rid from rinfo where Rin='0'and Rtype='标准单人间'
    select Rid from rinfo where Rin='0'and Rtype='标准双人间'
    select Rid from rinfo where Rin='0'and Rtype='商务套房'
    select Rid from rinfo where Rin='0'and Rtype='总统套房'
    GO    
                    SqlCommand cmd = new SqlCommand("RidSel", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddRange(values);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds);    string single = (string)ds.Tables[0].Rows[0][0];
        string doub = (string)ds.Tables[1].Rows[0][0];
        string business = (string)ds.Tables[2].Rows[0][0];
        string president = (string)ds.Tables[3].Rows[0][0];
      

  6.   

    //cmd.Parameters.AddRange(values);
    没有参数,这一行不要了
      

  7.   

    呵呵,终于解决了,dianjixue1兄的方法简单可行,不用输出参数,没想到这么简单,谢谢各位了