| |

VerySource

 Forgot password?
 Register
Search
View: 1795|Reply: 2

How to get the return value of Sybase stored procedure?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-7 22:00:02
| Show all posts |Read mode
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
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-29 19:00:02
| Show all posts
Wrongly written, my example returned 1 result set. To make the problem clearer, these are the code I simplified and debugged with this code. And summarized the law of the problem: first rdr.read (), if read, then ret must be equal to 0, otherwise you can get the return value.
Reply

Use magic Report

0

Threads

2

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2023-10-18 13:51:08
| Show all posts
帮你顶起来
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list