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个房间号都显示出来?
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
foreach (var i in ds.Tables[0].Rows)
{
MessaageBox.Show(i[0]);
}
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];
没有参数,这一行不要了