Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2007, 01:33 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default Returning a value (stored procedure

I am having problems populating my label with the return valueof a stored procedure.

This is the error I am getting:

String[1]: the Size property has an invalid size of 0.

EDIT: i changed the value of my varchar to 255 and now get the error:

Conversion failed when converting the varchar value 'test3 has been submitted successfully' to data type int.

I think it has to do with how i am converting the varchar to string but i am not sure.

My stored procedure:

ALTER PROCEDURE [dbo].[Add_Addresstype]
    -- Add the parameters for the stored procedure here
        @t_Addresstype VarChar(50),
        @t_return VarChar(255) OUTPUT

AS
BEGIN
    IF EXISTS (SELECT t_AddressType From CM_AddressType WHERE t_AddressType = @t_Addresstype)
BEGIN
    SET @t_return = 'The Address Type ' + @t_AddressType + ' already exists!'
    RETURN @t_return
END
ELSE
BEGIN
    INSERT INTO CM_AddressType (t_addresstype) VALUES (@t_AddressType)
    Set @t_return = @t_AddressType + ' has been submitted successfully'
    RETURN @t_return
END
END


the code i am using in c#

SqlConnection CRMConnectionString = new SqlConnection("Data Source=IRIS2;Initial Catalog=CRM;Persist Security Info=True;User ID=client;Password=w3bcl13nt");
        SqlCommand cmd = new SqlCommand("Add_AddressType", CRMConnectionString);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@t_AddressType", txtAddressType.Text);
        cmd.Parameters["@t_AddressType"].Value = txtAddressType.Text;
        cmd.Parameters.Add(new SqlParameter("@t_return", SqlDbType.VarChar, 255));
        cmd.Parameters["@t_return"].Direction = ParameterDirection.Output;
        CRMConnectionString.Open();
        cmd.ExecuteNonQuery();
        CRMConnectionString.Close();
        string t_return = cmd.Parameters["@t_return"].Value.ToString();
        lblreturn.Text = t_return;
 
Old November 7th, 2007, 02:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. what if you add the parameter @t_AddressType as a varchar too?? because you are not defining it when you pass the parameters...


HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 7th, 2007, 02:24 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

Thanks for your response. The insert of the text box entry is working but the return value of @t_return is failing with this error message:

"Conversion failed when converting the varchar value 'test5 has been submitted successfully' to data type int."

I am sorry if i missed the solution in your post. I am very new and dont always understand.


 
Old November 7th, 2007, 02:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

no problem.. what I see, is that somebody is casting that string to a int data type... (nothing new that you don't already knew).. anyway.. let's try figure out who is converting it... the error is on the SP or in your code?? what line throws it??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 7th, 2007, 02:40 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

Oh okay I think i see what your saying

 cmd.Parameters.Add(new SqlParameter("@t_return", SqlDbType.VarChar, 255));

This is the line that is defining it as int?

How would I make it Varchar? I thought this code
string t_return = cmd.Parameters["@t_return"].Value.ToString();
converted the varchar ToString ?

I also thought that c# didnt have varchar and i had to use string?



 
Old November 7th, 2007, 02:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Quote:
quote:Originally posted by scandalous
 cmd.Parameters.Add(new SqlParameter("@t_return", SqlDbType.VarChar, 255));
that line define it as a varchar..

Quote:
quote:
How would I make it Varchar? I thought this code
string t_return = cmd.Parameters["@t_return"].Value.ToString();
converted the varchar ToString ?
that code transform the object to a string.. maybe the object there is not a string??

I ask again.. which line is throwing the error????
if you trace the code.. where the compiler informs you of the error???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 7th, 2007, 02:53 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

the line that is highlighted is when i debug and press my button is

 cmd.ExecuteNonQuery();

is that what i am looking for. sorry again?

 
Old November 7th, 2007, 03:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I'm not an SP expert.. but maybe SQL is trying to map the return value to an int because executenonquery return the number of row affecteds??? what if you take out the return lines from the SP????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 7th, 2007, 03:36 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

OMG your so smart!! I commented out the RETURN lines and the output worked properly!! i get my message back and everything. any other suggestions you might be have regarding my code is welcomed. thank you so much!!

 
Old November 7th, 2007, 03:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

glad you solve it :)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Values from a Stored Procedure kadjw SQL Server ASP 1 September 13th, 2006 12:08 PM
Returning Stored Procedure Results from ASP page JennaAckerson Classic ASP Basics 0 December 23rd, 2005 11:44 AM
Problems returning count in Stored Procedure planza SQL Language 1 December 21st, 2005 03:24 PM
Stored Proceedure Returning A Recordset rodmcleay C# 3 July 5th, 2004 09:53 PM
Returning record in stored function with ADO nmbarbillo Oracle 0 June 15th, 2004 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.