Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Stored Procedures and OUTPUT Problems


Message #1 by "Douglas Rohm" <dlr@m...> on Thu, 13 Sep 2001 17:11:28 -0400
I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

cmd.CommandType = CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID");

prmMemID.Value = 0;

prmMemID.Direction = ParameterDirection.Output;

cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int.

I can not figure this out.  I have the Professional C# book and I'm

doing it EXACTLY like the book and I'm getting this error.  Can someone

help?

 

Douglas Rohm

dlr@m...
Message #2 by Todd Carrico <ToddC@m...> on Thu, 13 Sep 2001 16:18:07 -0500
Have you tried Int32.Parse?



Int32.Parse(cmd.Parameters["@memID"].Value);



tc





-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 4:11 PM

To: ASP+

Subject: [aspx] Stored Procedures and OUTPUT Problems



I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

cmd.CommandType = CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID");

prmMemID.Value = 0;

prmMemID.Direction = ParameterDirection.Output;

cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int.

I can not figure this out.  I have the Professional C# book and I'm

doing it EXACTLY like the book and I'm getting this error.  Can someone

help?

 

Douglas Rohm
Message #3 by "Julian Roberts" <jules@c...> on Thu, 13 Sep 2001 22:30:01 +0100
I had a similar issue yesterday. I don't think you can convert an object to

an int. I ended up using:



int mID = Int32.Parse(cmd.Parameters["@memID"].Value.ToString());





Julian Roberts

http://charon.co.uk

+44 (0)1743 885122





----- Original Message -----

From: "Douglas Rohm" <dlr@m...>

To: "ASP+" <aspx@p...>

Sent: Thursday, September 13, 2001 10:11 PM

Subject: [aspx] Stored Procedures and OUTPUT Problems





> I need help with a stored procedure that is returning output.

>

> Here's the code:

>





Message #4 by Tim Heuer <TimH@i...> on Thu, 13 Sep 2001 14:39:58 -0700
Try a few things differently:



SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 0) //try

using zero rather than 4



int mID = Convert.ToInt32(prmMemID.Value);



-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 2:11 PM

To: ASP+

Subject: [aspx] Stored Procedures and OUTPUT Problems





I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con); cmd.CommandType 

CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID"); prmMemID.Value = 0; prmMemID.Direction 

ParameterDirection.Output; cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int. I

can not figure this out.  I have the Professional C# book and I'm doing it

EXACTLY like the book and I'm getting this error.  Can someone help?

 

Douglas Rohm
Message #5 by "Douglas Rohm" <dlr@m...> on Thu, 13 Sep 2001 19:26:33 -0400
I've tried doing all of the different conversions that everyone

mentioned but still could not get it to work.  Until I can get it to

work, I'm going to simply change the OUTPUT to a varchar, which I've

done before and works fine.



If anyone knows how to get this to work, please let me know.  This is

ridiculous.



Doug



-----Original Message-----

From: Tim Heuer [mailto:TimH@i...] 

Sent: Thursday, September 13, 2001 5:40 PM

To: ASP+

Subject: [aspx] RE: Stored Procedures and OUTPUT Problems



Try a few things differently:



SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 0)

//try

using zero rather than 4



int mID = Convert.ToInt32(prmMemID.Value);



-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 2:11 PM

To: ASP+

Subject: [aspx] Stored Procedures and OUTPUT Problems





I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

cmd.CommandType 

CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID"); prmMemID.Value = 0; prmMemID.Direction 

ParameterDirection.Output; cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int.

I

can not figure this out.  I have the Professional C# book and I'm doing

it

EXACTLY like the book and I'm getting this error.  Can someone help?

 

Douglas Rohm
Message #6 by "Brzeski, Tom" <Tom.Brzeski@o...> on Fri, 14 Sep 2001 15:55:15 -0400
Try to pass your parameter as string not as int

I have similar VB code and it works fine





-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 4:27 PM

To: ASP+

Subject: [aspx] RE: Stored Procedures and OUTPUT Problems



I've tried doing all of the different conversions that everyone

mentioned but still could not get it to work.  Until I can get it to

work, I'm going to simply change the OUTPUT to a varchar, which I've

done before and works fine.



If anyone knows how to get this to work, please let me know.  This is

ridiculous.



Doug



-----Original Message-----

From: Tim Heuer [mailto:TimH@i...] 

Sent: Thursday, September 13, 2001 5:40 PM

To: ASP+

Subject: [aspx] RE: Stored Procedures and OUTPUT Problems



Try a few things differently:



SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 0)

//try

using zero rather than 4



int mID = Convert.ToInt32(prmMemID.Value);



-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 2:11 PM

To: ASP+

Subject: [aspx] Stored Procedures and OUTPUT Problems





I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

cmd.CommandType 

CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID"); prmMemID.Value = 0; prmMemID.Direction 

ParameterDirection.Output; cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int.

I

can not figure this out.  I have the Professional C# book and I'm doing

it

EXACTLY like the book and I'm getting this error.  Can someone help?

 

Douglas Rohm

Message #7 by "Tom Brzeski" <tom.brzeski@o...> on Fri, 14 Sep 2001 21:05:56
instead of int you need to use string. I'm using vb with string and it 

works fine

'===

dim strA as string="123"



            Dim parameterA As SqlParameter = New SqlParameter

("@SecurityLevel", SqlDbType.Int, 4)

            parameterA.Value = strA

            myCommand.Parameters.Add(A)

 







> I need help with a stored procedure that is returning output.

>  

> Here's the code:

>  

> SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

> cmd.CommandType = CommandType.StoredProcedure;

>  

> SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

> "memberID");

> prmMemID.Value = 0;

> prmMemID.Direction = ParameterDirection.Output;

> cmd.Parameters.Add(prmMemID);

>  

> con.Open();

> cmd.ExecuteNonQuery();

>  

> int mID = (int) cmd.Parameters["@memID"].Value;

> Trace.Write("@memID: ", mID.ToString());

>  

> if (mID > 0)

> {

>             FormsAuthentication.RedirectFromLoginPage(strUsername,

> chkPersist.Checked);

> }

>  

>  

> I'm getting the error when I try to cast the @memID parameter to an int.

> I can not figure this out.  I have the Professional C# book and I'm

> doing it EXACTLY like the book and I'm getting this error.  Can someone

> help?

>  

> Douglas Rohm

> dlr@m...
Message #8 by Todd Carrico <ToddC@m...> on Fri, 14 Sep 2001 15:18:28 -0500
DBType.Int32 is the corresponding data type to a SQL INT.  I have used this

with good results.



tc





-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 6:27 PM

To: ASP+

Subject: [aspx] RE: Stored Procedures and OUTPUT Problems



I've tried doing all of the different conversions that everyone

mentioned but still could not get it to work.  Until I can get it to

work, I'm going to simply change the OUTPUT to a varchar, which I've

done before and works fine.



If anyone knows how to get this to work, please let me know.  This is

ridiculous.



Doug



-----Original Message-----

From: Tim Heuer [mailto:TimH@i...] 

Sent: Thursday, September 13, 2001 5:40 PM

To: ASP+

Subject: [aspx] RE: Stored Procedures and OUTPUT Problems



Try a few things differently:



SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 0)

//try

using zero rather than 4



int mID = Convert.ToInt32(prmMemID.Value);



-----Original Message-----

From: Douglas Rohm [mailto:dlr@m...] 

Sent: Thursday, September 13, 2001 2:11 PM

To: ASP+

Subject: [aspx] Stored Procedures and OUTPUT Problems





I need help with a stored procedure that is returning output.

 

Here's the code:

 

SqlCommand cmd = new SqlCommand("sp_ValidateMember", con);

cmd.CommandType 

CommandType.StoredProcedure;

 

SqlParameter prmMemID = new SqlParameter("@memID", SqlDbType.Int, 4,

"memberID"); prmMemID.Value = 0; prmMemID.Direction 

ParameterDirection.Output; cmd.Parameters.Add(prmMemID);

 

con.Open();

cmd.ExecuteNonQuery();

 

int mID = (int) cmd.Parameters["@memID"].Value;

Trace.Write("@memID: ", mID.ToString());

 

if (mID > 0)

{

            FormsAuthentication.RedirectFromLoginPage(strUsername,

chkPersist.Checked);

}

 

 

I'm getting the error when I try to cast the @memID parameter to an int.

I

can not figure this out.  I have the Professional C# book and I'm doing

it

EXACTLY like the book and I'm getting this error.  Can someone help?

 

Douglas Rohm







  Return to Index