|
我写了一个存储过程,返回2个结果集和1个返回值, 代码如下:
if exists (select * from sysobjects where name='proc_tel_jboxdmt_query')
begin
drop proc proc_tel_jboxdmt_query
end
go
create proc proc_tel_jboxdmt_query
(@jbox_num char(20),
@begin_date datetime,
@end_date datetime
)
as
begin
declare @queryflag int
select @end_date = dateadd(dd, 1, @end_date)
if @begin_date >= @end_date
return -2001
--先验证编号有效性
if not exists (select * from device where device_name = @jbox_num and device_type = '1000')
begin
select @queryflag = 0
select @queryflag
return -1001
end
用如下代码执行并且获取存储过程:
OleDbParameter[] parms = new OleDbParameter[]
{
new OleDbParameter("@ret", OleDbType.Integer), //返回值
new OleDbParameter("@jbox_num", OleDbType.Char, 20), //编号
new OleDbParameter("@begin_date", OleDbType.Date), //开始时间
new OleDbParameter("@end_date", OleDbType.Date) //结束时间
};
parms[0].Direction = ParameterDirection.ReturnValue;
parms[1].Direction = ParameterDirection.Input;
parms[2].Direction = ParameterDirection.Input;
parms[3].Direction = ParameterDirection.Input;
parms[1].Value = jboxNum;
parms[2].Value = startDate;
parms[3].Value = endDate;
cmd = new OleDbCommand();
cmd.Connection = new OleDbConnection(OLEDB_CONN_STRING_ITSRP);
cmd.Connection.Open();
cmd.CommandText = SQL_TEL_JBOXDMT_QUERY;
cmd.CommandType = CommandType.Text;
foreach(OleDbParameter parm in parms)
{
cmd.Parameters.Add(parm);
}
rdr = cmd.ExecuteReader();
if(rdr.Read())
{
queryflag = rdr.GetString(0); }
rdr.Close();
ret = Convert.ToInt32(cmd.Parameters[0].Value);
如果去掉存储过程中: select @queryflag = 0
select @queryflag这两句,则获取的ret=-1001,加上则ret=0。不知何故,请高手指教!!十分着急啊,调试了1整天了,各种方法都试了,最后就发现只要返回了结果集,则返回值就等于0,奇怪啊
|
|