473,791 Members | 2,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot get OUTPUT parameter after running Sql stored procedure

MS
Here's my simple stored procedure:

ALTER PROCEDURE GetMemberIDByEm ail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
Here's my C# code (using Microsoft Data
public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

try
{
SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail", aryParams);
}
catch (System.Data.Sq lClient.SqlExce ption)
{
return 0;
}

if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}

return 0;
}
The value of the output parameter is ALWAYS null! I've spent hours trying to
fix this but don't see what is wrong. The stored procedure works great in
Query Analyzer. Can anyone point out what I'm missing? Thanks!

Can anyone
Nov 16 '05 #1
5 25402
Add a Trace.Writeline (ex.message)

catch (System.Data.Sq lClient.SqlExce ption ex)
{
System.Diagnost ics.Trace.Write line(ex.message )
return 0;
}
catch (Exception ex) // catch other errors
{
System.Diagnost ics.Trace.Write line(ex.message )
}
"MS" <tu**********@g mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Here's my simple stored procedure:

ALTER PROCEDURE GetMemberIDByEm ail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
Here's my C# code (using Microsoft Data
public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

try
{
SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail",
aryParams);
}
catch (System.Data.Sq lClient.SqlExce ption)
{
return 0;
}

if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}

return 0;
}
The value of the output parameter is ALWAYS null! I've spent hours trying
to fix this but don't see what is wrong. The stored procedure works great
in Query Analyzer. Can anyone point out what I'm missing? Thanks!

Can anyone

Nov 16 '05 #2
I think that this code is simply but ok!

public void method()
{
SqlConnection mainConn = new SqlConnection() ;
mainConn.Connec tionString = "user id=sa;password= pippo;initial
catalog=myDB;da ta source=(local)" ;

if (mainConn.State == ConnectionState .Closed)
mainConn.Open() ;

try
{
SqlCommand myCmd = new SqlCommand("sto redProc",mainCo nn);
myCmd.CommandTy pe = CommandType.Sto redProcedure;
SqlParameter ret = new SqlParameter("@ RETURN", SqlDbType.Int);
ret.Direction = ParameterDirect ion.ReturnValue ;
myCmd.Parameter s["@parameter s"].Value = ValueOfParamete rs;
myCmd.ExecuteNo nQuery();

int var = (int)ret.Value;
}
catch (Exception ex)
{
MessageBox.Show ("" + ex.Message);
}
finally
{
mainConn.Close( );
}
}

I use this statemet when i must use stored procedure!
I hope that this code is well for you!

Good bye

"MS" wrote:
Here's my simple stored procedure:

ALTER PROCEDURE GetMemberIDByEm ail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
Here's my C# code (using Microsoft Data
public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

try
{
SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail", aryParams);
}
catch (System.Data.Sq lClient.SqlExce ption)
{
return 0;
}

if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}

return 0;
}
The value of the output parameter is ALWAYS null! I've spent hours trying to
fix this but don't see what is wrong. The stored procedure works great in
Query Analyzer. Can anyone point out what I'm missing? Thanks!

Can anyone

Nov 16 '05 #3
Hello,
in code u are missing a statement saying

aryParms[0].value = so*******@abc.c om;

because you are not passing anything into the stored procedure for email. so
sp doesnt return anything here.
try this good luck.
bye

--
Srinivas L.Kollipara
"MS" <tu**********@g mail.com> wrote in message
news:#o******** ******@TK2MSFTN GP11.phx.gbl...
Here's my simple stored procedure:

ALTER PROCEDURE GetMemberIDByEm ail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
Here's my C# code (using Microsoft Data
public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

try
{
SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail", aryParams); }
catch (System.Data.Sq lClient.SqlExce ption)
{
return 0;
}

if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}

return 0;
}
The value of the output parameter is ALWAYS null! I've spent hours trying to fix this but don't see what is wrong. The stored procedure works great in
Query Analyzer. Can anyone point out what I'm missing? Thanks!

Can anyone

Nov 16 '05 #4
I don't think you're actually passing the email value in that you think you
are.

I don't have any experience passing parameters when the defined SQL type is
a user defined type. I assume that in C# you would have to use the actual
underlying SQL type. If that were, say, varchar, your code would look like
this:

aryParams[0] = new
SqlParameter("@ Email",SqlDbTyp e.Varchar,email .Length).Value = email;

Give that a try.

--Bob

"MS" <tu**********@g mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Here's my simple stored procedure:

ALTER PROCEDURE GetMemberIDByEm ail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
Here's my C# code (using Microsoft Data
public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

try
{
SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail",
aryParams);
}
catch (System.Data.Sq lClient.SqlExce ption)
{
return 0;
}

if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}

return 0;
}
The value of the output parameter is ALWAYS null! I've spent hours trying
to fix this but don't see what is wrong. The stored procedure works great
in Query Analyzer. Can anyone point out what I'm missing? Thanks!

Can anyone

Nov 16 '05 #5
> public int GetMemberIdByEm ail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];

aryParams[0] = new SqlParameter("@ Email", email);
aryParams[1] = new SqlParameter("@ ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirect ion.Output;

SqlHelper.Execu teNonQuery(_Con nection, "GetMemberIDByE mail", aryParams);
if (aryParams[1].Value == null)
{
Debug.WriteLine ("Still NULL!"); <-- ALWAYS GET THIS!!
}
else
{
Debug.WriteLine ("Got it!");
}


You're using the wrong overload for ExecuteNonQuery - the one that
uses a "params object[]......" array (overload no. 4), not the one
using the SqlParameter[] array! (that would be overload no. 5).

In this case, the ExecuteNonQuery call does not know what kind of
parameters you've passed in, and thus cannot update them upon exiting.

Use this call instead:

SqlHelper.Execu teNonQuery(_Con nection, CommandType.Sto redProcedure,
"GetMemberIDByE mail", aryParams);

*THEN* you should be able to access your output parameter.

Marc

=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 16 '05 #6

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

Similar topics

1
11593
by: Sandie Towers | last post by:
We use a number of similar databases and frequently create a new database using a backup restore of another similar database. We try to keep changes between databases in _Additional tables - like Account Additional, Sale_Additional so most tables stay the same. The latest restored database (I'll call it DBaseA) is behaving differently in VB6 code and I need help trying to make it work. I have been using use an ADODB.Command to execute...
8
5483
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
4
45147
by: laurenq uantrell | last post by:
I need to get the value of an output parameter back into my VBA function calling a stored procedure. I'm using the following construction to append a new record in a SQL Server table: Function ThisFunctionInsertsANewRecord() On Error GoTo myErr Dim cmd As ADODB.Command
8
14022
by: Yusuf INCEKARA | last post by:
I have a stored procedure : CREATE PROCEDURE STP_GETSTORELIST @RETCUR CURSOR VARYING OUTPUT AS set @RETCUR = CURSOR FORWARD_ONLY STATIC FOR SELECT ID,STORE_NAME FROM T_INF_STORE ORDER BY STORE_NAME OPEN @RETCUR
8
4457
by: Christopher Weaver | last post by:
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
5
6522
by: MS | last post by:
Here's my simple stored procedure: ALTER PROCEDURE GetMemberIDByEmail @Email EmailAddress, @ID int OUTPUT AS SELECT @ID = ID FROM tbl_Member WHERE Email=@Email RETURN
4
50417
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList varchar(7) output AS select @out_eList = ecuid from _organization where rccode = @in_rc GO
0
19295
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
1
12323
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 poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my code behind, evaluating the necessary bound fields. The problem is the SqlDataSource representing...
1
2026
by: Mike P | last post by:
I am trying to return an output parameter to my code on executing a stored procedure. In Query Analyzer, it works with no problem, but when I run my ASP code below, the output parameter never seems to return anything. Can anybody help? Dim cmdNewCampaign, rsNewCampaign, intNumber Const adCmdStoredProc = &H0004 Const adParamInput = &H0001 Const adParamOutput = &H0002 Const adVarChar = 200
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
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 we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.