|
I wrote a stored procedure that returns 2 result sets and 1 return value. The code is as follows:
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
-First verify the validity of the number
if not exists (select * from device where device_name = @jbox_num and device_type = '1000')
begin
select @queryflag = 0
select @queryflag
return -1001
end
Execute and retrieve the stored procedure with the following code:
OleDbParameter [] parms = new OleDbParameter []
{
new OleDbParameter ("@ ret", OleDbType.Integer), // Return value
new OleDbParameter ("@ jbox_num", OleDbType.Char, 20), // number
new OleDbParameter ("@ begin_date", OleDbType.Date), // start time
new OleDbParameter ("@ end_date", OleDbType.Date) // end time
};
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);
If you remove the stored procedure: select @queryflag = 0
Select @queryflag, get ret = -1001, plus ret = 0. Somehow, please enlighten me! !! Very anxious, debugged for a whole day, tried various methods, and finally found that as long as the result set is returned, the return value is equal to 0, strange |
|