Return sql-variable?

L

Lasse Edsvik

Hello

I was wondering if you guys know how to retrieve a returned sql-variable in
the asp.net?

CREATE PROCEDURE......
@A int output
AS
....
SELECT @A=1
.....


TIA
/Lasse
 
G

Guest

Hi Lasse,

Try this on your code;

oConn.Open();
try {
SqlCommand cmd = new SqlCommand("MySproc", oConn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@myOutPut", SqlDbType.Int);
param.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
Response.Write(cmd.Parameters["@myOutPut"].Value);
}
finally {
oConn.Close();
}

Your SP should look like below;

CREATE PROCEDURE dbo.MySproc (
@myOutPut int output
)

AS

Select ...


Set @myOutPut = ... --Whatever you want


Hope this helps,

Ethem
 
L

Lasse Edsvik

Ethem,

thanks :)


Ethem Azun said:
Hi Lasse,

Try this on your code;

oConn.Open();
try {
SqlCommand cmd = new SqlCommand("MySproc", oConn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@myOutPut", SqlDbType.Int);
param.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
Response.Write(cmd.Parameters["@myOutPut"].Value);
}
finally {
oConn.Close();
}

Your SP should look like below;

CREATE PROCEDURE dbo.MySproc (
@myOutPut int output
)

AS

Select ...


Set @myOutPut = ... --Whatever you want


Hope this helps,

Ethem

Lasse Edsvik said:
Hello

I was wondering if you guys know how to retrieve a returned sql-variable in
the asp.net?

CREATE PROCEDURE......
@A int output
AS
....
SELECT @A=1
.....


TIA
/Lasse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top