.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 7th, 2007, 12:59 PM
Antoniops Antoniops is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 2 Antoniops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 7 sec
Reputation Power: 0
Exclamation C# ado stored procedure (return messgae)

I am trying to make a simple asp.net page that shows a grid view, textbox to enter a new item and a button that submits it through a stored procedure and populates an output parameter in a label. I am right now getting an error:

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

I am very new to programming so all suggestions are welcome. I havent found a tutorial for using varchar so if you know of one let me know

=============
Storedprocedure
=============
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

=============
c# Code
=============
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;

Reply With Quote
  #2  
Old November 7th, 2007, 02:39 PM
Antoniops Antoniops is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 2 Antoniops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 7 sec
Reputation Power: 0
Strange.....I commented ou the RETURN lines and it works now. i get my message and everything!

How would i refresh my gridview after the procedure is finisheD?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > C# ado stored procedure (return messgae)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT