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
Here's my C# code (using Microsoft Data
public int GetMemberIdByEmail(string email)
{
SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email);
aryParams[1] = new SqlParameter("@ID", SqlDbType.Int);
aryParams[1].Direction = ParameterDirection.Output;
try
{
SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail", aryParams);
}
catch (System.Data.SqlClient.SqlException)
{
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 5 25337
Add a Trace.Writeline(ex.message)
catch (System.Data.SqlClient.SqlException ex)
{
System.Diagnostics.Trace.Writeline(ex.message)
return 0;
}
catch (Exception ex) // catch other errors
{
System.Diagnostics.Trace.Writeline(ex.message)
}
"MS" <tu**********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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
Here's my C# code (using Microsoft Data
public int GetMemberIdByEmail(string email) { SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email); aryParams[1] = new SqlParameter("@ID", SqlDbType.Int); aryParams[1].Direction = ParameterDirection.Output;
try { SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail", aryParams); } catch (System.Data.SqlClient.SqlException) { 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
I think that this code is simply but ok!
public void method()
{
SqlConnection mainConn = new SqlConnection();
mainConn.ConnectionString = "user id=sa;password=pippo;initial
catalog=myDB;data source=(local)";
if (mainConn.State == ConnectionState.Closed)
mainConn.Open();
try
{
SqlCommand myCmd = new SqlCommand("storedProc",mainConn);
myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ret = new SqlParameter("@RETURN", SqlDbType.Int);
ret.Direction = ParameterDirection.ReturnValue;
myCmd.Parameters["@parameters"].Value = ValueOfParameters;
myCmd.ExecuteNonQuery();
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 GetMemberIDByEmail @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 GetMemberIdByEmail(string email) { SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email); aryParams[1] = new SqlParameter("@ID", SqlDbType.Int); aryParams[1].Direction = ParameterDirection.Output;
try { SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail", aryParams); } catch (System.Data.SqlClient.SqlException) { 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
Hello,
in code u are missing a statement saying
aryParms[0].value = so*******@abc.com;
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**********@gmail.com> wrote in message
news:#o**************@TK2MSFTNGP11.phx.gbl... 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
Here's my C# code (using Microsoft Data
public int GetMemberIdByEmail(string email) { SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email); aryParams[1] = new SqlParameter("@ID", SqlDbType.Int); aryParams[1].Direction = ParameterDirection.Output;
try { SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail",
aryParams); } catch (System.Data.SqlClient.SqlException) { 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
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",SqlDbType.Varchar,email.Leng th).Value = email;
Give that a try.
--Bob
"MS" <tu**********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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
Here's my C# code (using Microsoft Data
public int GetMemberIdByEmail(string email) { SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email); aryParams[1] = new SqlParameter("@ID", SqlDbType.Int); aryParams[1].Direction = ParameterDirection.Output;
try { SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail", aryParams); } catch (System.Data.SqlClient.SqlException) { 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
> public int GetMemberIdByEmail(string email) { SqlParameter[] aryParams = new SqlParameter[2];
aryParams[0] = new SqlParameter("@Email", email); aryParams[1] = new SqlParameter("@ID", SqlDbType.Int); aryParams[1].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(_Connection, "GetMemberIDByEmail", 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.ExecuteNonQuery(_Connection, CommandType.StoredProcedure,
"GetMemberIDByEmail", 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
--------------------------------------------------------------------------------
...
|
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:
...
|
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...
|
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
|
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
|
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...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |