473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing Output Parameter Value

I'm having trouble accessing the value of an output parameter of a stored
procedure. The SP looks like this:

SET TERM ^ ;

CREATE PROCEDURE SP_NEW_TASK
RETURNS (
"uidTask" INTEGER)
AS
begin
INSERT INTO "tblTasks" ( "Description", "AddDate", "DueDate", "Status")
VALUES('New task', 'now', 'now', 'Open');

SELECT MAX("uidTask")
FROM "tblTasks"
INTO :"uidTask";

UPDATE "tblTasks"
SET "AssignToSeq" = - :"uidTask"
WHERE "uidTask" = :"uidTask";

suspend;
end
^

SET TERM ; ^

GRANT SELECT,INSERT,UPDATE ON "tblTasks" TO PROCEDURE SP_NEW_TASK;

GRANT EXECUTE ON PROCEDURE SP_NEW_TASK TO SYSDBA;

And I'm running it like this:

CreateNewTask.Connection = odbcIB;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "EXECUTE PROCEDURE \"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID", OdbcType.Int);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

CreateNewTask.Connection.Open();
CreateNewTask.ExecuteNonQuery();
CreateNewTask.Connection.Close();

Any ideas on this? I can't find even a single example of accessing the
value of an output parameter when running a stored procedure within MSDN.
Pointing me toward one in C# would be great!

Thanks
Nov 17 '05 #1
8 4435
Christopher,

First, you should set the command text of the command to just the name
of the stored procedure. You don't need to do anything else in that regard.

The other thing that you want to do is set the Direction to
ParameterDirection.ReturnValue. Once you do this and run the stored
procedure, you should be able to access the parameter's value through the
Value property on the parameter.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Christopher Weaver" <we*****@nospamverizon.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm having trouble accessing the value of an output parameter of a stored
procedure. The SP looks like this:

SET TERM ^ ;

CREATE PROCEDURE SP_NEW_TASK
RETURNS (
"uidTask" INTEGER)
AS
begin
INSERT INTO "tblTasks" ( "Description", "AddDate", "DueDate", "Status")
VALUES('New task', 'now', 'now', 'Open');

SELECT MAX("uidTask")
FROM "tblTasks"
INTO :"uidTask";

UPDATE "tblTasks"
SET "AssignToSeq" = - :"uidTask"
WHERE "uidTask" = :"uidTask";

suspend;
end
^

SET TERM ; ^

GRANT SELECT,INSERT,UPDATE ON "tblTasks" TO PROCEDURE SP_NEW_TASK;

GRANT EXECUTE ON PROCEDURE SP_NEW_TASK TO SYSDBA;

And I'm running it like this:

CreateNewTask.Connection = odbcIB;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "EXECUTE PROCEDURE \"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID", OdbcType.Int);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

CreateNewTask.Connection.Open();
CreateNewTask.ExecuteNonQuery();
CreateNewTask.Connection.Close();

Any ideas on this? I can't find even a single example of accessing the
value of an output parameter when running a stored procedure within MSDN.
Pointing me toward one in C# would be great!

Thanks

Nov 17 '05 #2
Hi, Christopher,

For obtaining the value of an output parameter, you can use the same syntax
that for setting it:

cmd.Parameters["Input"].Value = 25;
cmd.ExecuteNonQuery();
int result = (int) cmd.Parameters["Output"].Value;

In your case, this should work:

int taskID = (int) CreateNewTask.Parameters["NewTaskID"];

You're using InterBase, right?

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:%2****************@tk2msftngp13.phx.gbl...
I'm having trouble accessing the value of an output parameter of a stored
procedure. The SP looks like this:

SET TERM ^ ;

CREATE PROCEDURE SP_NEW_TASK
RETURNS (
"uidTask" INTEGER)
AS
begin
INSERT INTO "tblTasks" ( "Description", "AddDate", "DueDate", "Status")
VALUES('New task', 'now', 'now', 'Open');

SELECT MAX("uidTask")
FROM "tblTasks"
INTO :"uidTask";

UPDATE "tblTasks"
SET "AssignToSeq" = - :"uidTask"
WHERE "uidTask" = :"uidTask";

suspend;
end
^

SET TERM ; ^

GRANT SELECT,INSERT,UPDATE ON "tblTasks" TO PROCEDURE SP_NEW_TASK;

GRANT EXECUTE ON PROCEDURE SP_NEW_TASK TO SYSDBA;

And I'm running it like this:

CreateNewTask.Connection = odbcIB;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "EXECUTE PROCEDURE \"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID", OdbcType.Int);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

CreateNewTask.Connection.Open();
CreateNewTask.ExecuteNonQuery();
CreateNewTask.Connection.Close();

Any ideas on this? I can't find even a single example of accessing the
value of an output parameter when running a stored procedure within MSDN.
Pointing me toward one in C# would be great!

Thanks

Nov 17 '05 #3
Sorry, I missed '.Value' in my last post:

int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;

As Nicholas says, in CommandText you only need to have the NAME of the
stored procedure.

Regards - Octavio
Nov 17 '05 #4
> You're using InterBase, right?
How did you know?
As Nicholas says, in CommandText you only need to have the NAME of the
stored procedure. That's never worked for me. I think the problem is in the odbc driver that
comes with InterBase.
int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;

This compiles but throws "Specified cast is not valid." What's more, this
line:

DataType = CreateNewTask.Parameters["NewTaskID"].OdbcType.ToString();

returns "Int" in my catch message:

catch (Exception ex)
{
MessText = ex.Message + "\n" + ParamValue + "\n" + DataType;
MessageBox.Show(MessText);
}

ParamValue comes from

ParamValue = CreateNewTask.Parameters["NewTaskID"].Value.ToString();

And it's always null. I'm concerned about this last point. Seems it
shouldn't be null. The back end is creating a new record each time.

Thanks for your help. Yours and Nicholas. Any more ideas would be great.
Nov 17 '05 #5
Christopher,

I knew it was InterBase for the SET TERM statement.
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET provider
supplied by Borland?

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:Om**************@TK2MSFTNGP12.phx.gbl...
You're using InterBase, right?

How did you know?
As Nicholas says, in CommandText you only need to have the NAME of the
stored procedure.

That's never worked for me. I think the problem is in the odbc driver
that comes with InterBase.
int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;

This compiles but throws "Specified cast is not valid." What's more, this
line:

DataType = CreateNewTask.Parameters["NewTaskID"].OdbcType.ToString();

returns "Int" in my catch message:

catch (Exception ex)
{
MessText = ex.Message + "\n" + ParamValue + "\n" + DataType;
MessageBox.Show(MessText);
}

ParamValue comes from

ParamValue = CreateNewTask.Parameters["NewTaskID"].Value.ToString();

And it's always null. I'm concerned about this last point. Seems it
shouldn't be null. The back end is creating a new record each time.

Thanks for your help. Yours and Nicholas. Any more ideas would be great.

Nov 17 '05 #6
> ¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET provider
supplied by Borland?
Voila!

Doesn't say much for the odbc driver, does it. I will be rewriting my
entire app to removed all uses of the odbc driver to avoid any other
problems that haven't surfaced yet.

It turns out like this: (with some exception catching left out)

BdpConnection Conn = GetBdpConnection();
BdpCommand CreateNewTask = new BdpCommand();
CreateNewTask.Connection = Conn;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "\"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID",Borland.D ata.Common.BdpType.Int32);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

Thanks,

Chris.
"Octavio Hernandez" <do****@danysoft.com> wrote in message
news:Oj*************@TK2MSFTNGP12.phx.gbl... Christopher,

I knew it was InterBase for the SET TERM statement.
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET provider
supplied by Borland?

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:Om**************@TK2MSFTNGP12.phx.gbl...
You're using InterBase, right?

How did you know?
As Nicholas says, in CommandText you only need to have the NAME of the
stored procedure.

That's never worked for me. I think the problem is in the odbc driver
that comes with InterBase.
int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;

This compiles but throws "Specified cast is not valid." What's more,
this line:

DataType = CreateNewTask.Parameters["NewTaskID"].OdbcType.ToString();

returns "Int" in my catch message:

catch (Exception ex)
{
MessText = ex.Message + "\n" + ParamValue + "\n" + DataType;
MessageBox.Show(MessText);
}

ParamValue comes from

ParamValue = CreateNewTask.Parameters["NewTaskID"].Value.ToString();

And it's always null. I'm concerned about this last point. Seems it
shouldn't be null. The back end is creating a new record each time.

Thanks for your help. Yours and Nicholas. Any more ideas would be
great.


Nov 17 '05 #7
Christopher,

If you're using Borland Delphi 2005 I seriously recommend you to use the
BDP.NET Provider... I think it's the BEST way with difference to access
InterBase from .NET applications. I've tried it and it works quite well.
Also know of several customers using it without problems.

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:OA****************@TK2MSFTNGP10.phx.gbl...
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET provider
supplied by Borland?


Voila!

Doesn't say much for the odbc driver, does it. I will be rewriting my
entire app to removed all uses of the odbc driver to avoid any other
problems that haven't surfaced yet.

It turns out like this: (with some exception catching left out)

BdpConnection Conn = GetBdpConnection();
BdpCommand CreateNewTask = new BdpCommand();
CreateNewTask.Connection = Conn;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "\"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID",Borland.D ata.Common.BdpType.Int32);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

Thanks,

Chris.
"Octavio Hernandez" <do****@danysoft.com> wrote in message
news:Oj*************@TK2MSFTNGP12.phx.gbl...
Christopher,

I knew it was InterBase for the SET TERM statement.
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET provider
supplied by Borland?

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:Om**************@TK2MSFTNGP12.phx.gbl...
You're using InterBase, right?
How did you know?

As Nicholas says, in CommandText you only need to have the NAME of the
stored procedure.
That's never worked for me. I think the problem is in the odbc driver
that comes with InterBase.

int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;
This compiles but throws "Specified cast is not valid." What's more,
this line:

DataType = CreateNewTask.Parameters["NewTaskID"].OdbcType.ToString();

returns "Int" in my catch message:

catch (Exception ex)
{
MessText = ex.Message + "\n" + ParamValue + "\n" + DataType;
MessageBox.Show(MessText);
}

ParamValue comes from

ParamValue = CreateNewTask.Parameters["NewTaskID"].Value.ToString();

And it's always null. I'm concerned about this last point. Seems it
shouldn't be null. The back end is creating a new record each time.

Thanks for your help. Yours and Nicholas. Any more ideas would be
great.



Nov 17 '05 #8
I am unfortunately writing in VS 2003. It's not all that bad really, but
I've been with Delphi since D1 and taught it up through D6. But my client
wanted VS so I'm learning VS.

Thanks again.
"Octavio Hernandez" <do****@danysoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Christopher,

If you're using Borland Delphi 2005 I seriously recommend you to use the
BDP.NET Provider... I think it's the BEST way with difference to access
InterBase from .NET applications. I've tried it and it works quite well.
Also know of several customers using it without problems.

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:OA****************@TK2MSFTNGP10.phx.gbl...
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET
provider supplied by Borland?


Voila!

Doesn't say much for the odbc driver, does it. I will be rewriting my
entire app to removed all uses of the odbc driver to avoid any other
problems that haven't surfaced yet.

It turns out like this: (with some exception catching left out)

BdpConnection Conn = GetBdpConnection();
BdpCommand CreateNewTask = new BdpCommand();
CreateNewTask.Connection = Conn;
CreateNewTask.CommandType = CommandType.StoredProcedure;
CreateNewTask.CommandText = "\"SP_NEW_TASK\"";
CreateNewTask.Parameters.Add("NewTaskID",Borland.D ata.Common.BdpType.Int32);
CreateNewTask.Parameters["NewTaskID"].Direction =
System.Data.ParameterDirection.Output;

Thanks,

Chris.
"Octavio Hernandez" <do****@danysoft.com> wrote in message
news:Oj*************@TK2MSFTNGP12.phx.gbl...
Christopher,

I knew it was InterBase for the SET TERM statement.
¿Are you using the Odbc provider? ¿Why don't you use the ADO.NET
provider supplied by Borland?

Regards - Octavio

"Christopher Weaver" <we*****@nospamverizon.net> escribió en el mensaje
news:Om**************@TK2MSFTNGP12.phx.gbl...
> You're using InterBase, right?
How did you know?

>As Nicholas says, in CommandText you only need to have the NAME of the
>stored procedure.
That's never worked for me. I think the problem is in the odbc driver
that comes with InterBase.

>int taskID = (int) CreateNewTask.Parameters["NewTaskID"].Value;
This compiles but throws "Specified cast is not valid." What's more,
this line:

DataType = CreateNewTask.Parameters["NewTaskID"].OdbcType.ToString();

returns "Int" in my catch message:

catch (Exception ex)
{
MessText = ex.Message + "\n" + ParamValue + "\n" + DataType;
MessageBox.Show(MessText);
}

ParamValue comes from

ParamValue = CreateNewTask.Parameters["NewTaskID"].Value.ToString();

And it's always null. I'm concerned about this last point. Seems it
shouldn't be null. The back end is creating a new record each time.

Thanks for your help. Yours and Nicholas. Any more ideas would be
great.



Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString(...
5
by: vivienne.netherwood | last post by:
I am developing an Access Project front end with a SQL server database. I have written a stored procedure that returns a record set and also a value via an output parameter. The procedure is as...
8
by: Patreek | last post by:
Hi, On the line where I'm assigning RecordCount to be the value of my output parameter, I'm getting the generic "Object reference not set to an instance of an object" error. I've isolated it...
4
by: Tifer | last post by:
Hello, I'm still new to the whole .Net thing and I'm having a problem with something that should be so simple -- executing a query and returning an output parameter. It's a standard "Add"...
0
by: rockdale | last post by:
Hi, All How to get the output parameter's value when you use the SQLHelper (Microsoft Data Access Block)? When I try to access my ourput parm I got the following error. ...
8
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
4
by: Clint Pidlubny | last post by:
Hello, I'm using ASP.Net 2.0 and the Jan 2006 Enterprise Library. What I'm doing is passing an ArrayList into a stroed procedure to do an Insert. Here's some code: Dim params as New...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.