954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sql output stored procedure

I am writing an output stored procedure that i access using c#. I am trying to print the output values from the stored procedure.

using (SqlConnection connection = new SqlConnection(connectionstring))
        {
            connection.Open();            
            SqlCommand emailcmdsql;
            emailcmdsql = new SqlCommand("returnemail", connection);
            emailcmdsql.CommandType = CommandType.StoredProcedure;
            SqlParameter paruser = emailcmdsql.Parameters.Add("@user", SqlDbType.VarChar);
            paruser.Value = username.Text;
            paruser.Direction = ParameterDirection.Input;
            SqlParameter paremail = emailcmdsql.Parameters.Add("@email", SqlDbType.VarChar);
            paremail.Direction = ParameterDirection.Output;
            SqlParameter parpassword = emailcmdsql.Parameters.Add("@password", SqlDbType.VarChar);
            parpassword.Direction = ParameterDirection.Output;
                emailcmdsql.ExecuteNonQuery();
                string email = paremail.Value.ToString();
                string password = parpassword.Value.ToString();
                MessageBox.Show(email);
                MessageBox.Show(password);                  
        connection.Close();
}


below is the stored procedure

Alter PROCEDURE [dbo].returnemail
	@user varchar(30),
	@email varchar(50) OUTPUT,
	@password varchar (20) OUTPUT	
AS
BEGIN
	SET NOCOUNT ON;
  	SELECT @email = email, @password = password from ESS where username = @user
END


Please tell me what i'm doing wrong. I am getting this error.

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

asha2009
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

You have to specify the size argument.

SqlParameter paruser = emailcmdsql.Parameters.Add("@user", SqlDbType.VarChar,30);
....
SqlParameter paremail = emailcmdsql.Parameters.Add("@email", SqlDbType.VarChar,50);
...
SqlParameter parpassword = emailcmdsql.Parameters.Add("@password", SqlDbType.VarChar,30);
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: