Click here to Skip to main content
15,887,975 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I'm gettin' this error :
Procedure or function 'RegistrationProcedure' expects parameter '@firstname', which was not supplied.

Stored Procedure :
SQL
ALTER PROCEDURE dbo.RegistrationProcedure
	
	@user_id varchar (10),
	@firstname varchar (50),
	@lastname varchar (50),
	@password varchar (50),
	@email varchar(50),
	@address1 varchar (255),
	@address2 varchar (255),
	@job_function varchar (50),
	@city varchar (50),
	@state varchar (50),
	@zip varchar (10),
	@country varchar (50),
	@user_active  varchar (1),
	@user_intemail varchar (1),
	@user_added date,
	@user_last_logged_in datetime,
	@user_updated date,
	@user_group varchar(1),
	@user_comment varchar(max),
	@user_title varchar (50),
	@user_password_temp varchar (50),
	@is_login char(1),
	@paraIVtype varchar (100),
	@activationdt date,
	@expirydate date,
	@company_name varchar (50)
	
AS
	SET NOCOUNT ON;
	
	INSERT INTO users  (user_id, user_name_first, user_name_last, user_password, user_email, user_address1, user_address2, user_job, user_city,
							user_state, user_zip, user_country, user_active, user_intemail, user_added, user_last_logged_in, user_updated, user_group,
							user_comment, user_title, user_password_temp, is_login, paraivusertype, activationdt, expirydt, company)
							
			VALUES(@user_id, @firstname, @lastname, @password, @email, @address1, @address2, @job_function, @city,@state,@zip,@country,
				 @user_active, @user_intemail, @user_added, @user_last_logged_in, @user_updated, @user_group, @user_comment, @user_title,
				 @user_password_temp, @is_login, @paraIVtype, @activationdt, @expirydate, @company_name)
		RETURN

Data Class :
con.Open();
            SqlCommand cmd = new SqlCommand("RegistrationProcedure", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@user_id", 10);
            cmd.Parameters.AddWithValue("@user_firstname", firstname);
            cmd.Parameters.AddWithValue("@user_lastname", lastname);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.AddWithValue("@user_email", email);
            cmd.Parameters.AddWithValue("@user_address1","");
            cmd.Parameters.AddWithValue("@user_address2","");
            cmd.Parameters.AddWithValue("@job_function", job_function);
            cmd.Parameters.AddWithValue("@city", city);
            cmd.Parameters.AddWithValue("@state", "");
            cmd.Parameters.AddWithValue("@zip", "");
            cmd.Parameters.AddWithValue("@country", country);
            cmd.Parameters.AddWithValue("@user_active", "");
            cmd.Parameters.AddWithValue("@user_intemail", "");
            cmd.Parameters.AddWithValue("@user_added", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@user_last_logged_in", "");
            cmd.Parameters.AddWithValue("@user_updated", "");
            cmd.Parameters.AddWithValue("@user_group", "");
            cmd.Parameters.AddWithValue("@user_comment", "");
            cmd.Parameters.AddWithValue("@user_title", title);
            cmd.Parameters.AddWithValue("@user_password_temp", "");
            cmd.Parameters.AddWithValue("@is_login", "");
            cmd.Parameters.AddWithValue("@paraIVtype", "");
            cmd.Parameters.AddWithValue("@activationdt",DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@expirydate",DateTime.Now.AddYears(10));
            cmd.Parameters.AddWithValue("@company", company);


            cmd.ExecuteNonQuery();

            con.Close();

Business Class :
C#
string email, password, title, firstname, lastname, company, city, country, job_function;

        public string GetEmail
        {
            get
            {
                return email;
            }
            set
            {
                email = value;
            }
        }

        public string GetPassword
        {
            get
            {
                return password;
            }
            set
            {
                password = value;
            }
        }

        public string GetTitle
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }

        public string GetFirstName
        {
            get
            {
                return firstname;
            }
            set
            {
                firstname = value;
            }
        }

        public string GetLastName
        {
            get
            {
                return lastname;
            }
            set
            {
                lastname = value;
            }
        }

        public string GetCompany
        {
            get
            {
                return company;
            }
            set
            {
                company = value;
            }
        }

        public string GetCity
        {
            get
            {
                return city;
            }
            set
            {
                city = value;
            }
        }

        public string GetCountry
        {
            get
            {
                return country;
            }
            set
            {
                country = value;
            }
        }

        public string GetJobFunction
        {
            get
            {
                return job_function;
            }
            set
            {
                job_function = value;
            }
        }

        public void Registration()
        {
            dc.doRegistration(GetEmail, GetPassword, GetTitle, GetFirstName, GetLastName, GetCompany, GetCity, GetCountry, GetJobFunction);
        }


Presentation :
C#
protected void submitregistrationbtn_Click(object sender, EventArgs e)
        {
            bc.GetEmail = registerverifyemailtxt.Text;
            bc.GetPassword = registerverifypasswordtxt.Text;
            bc.GetTitle = registertitledropdown.SelectedItem.ToString();
            bc.GetFirstName = registerfnametxt.Text;
            bc.GetLastName = registerlnametxt.Text;
            bc.GetCompany = registerconametxt.Text;
            bc.GetCity = registercitytxt.Text;
            bc.GetCountry = registercountrydropdown.SelectedItem.ToString();
            bc.GetJobFunction = registerjobdropdown.SelectedItem.ToString();

            bc.Registration();
        }


Please correct me, Whats wrong here ???
Posted

I believe you need to replace

C#
cmd.Parameters.AddWithValue("@user_firstname", firstname);
cmd.Parameters.AddWithValue("@user_lastname", lastname);


with

C#
cmd.Parameters.AddWithValue("@firstname", firstname);
cmd.Parameters.AddWithValue("@lastname", lastname);


Hope that helps. If it does, mark it as answer/upvote.
Milind
 
Share this answer
 
Comments
[no name] 4-Dec-12 6:56am    
It helped... I'm new to stored procedure thats why it happened, Anyway ty man :)
MT_ 4-Dec-12 6:58am    
Glad I could help. Cheers :-)
Hi dear,

Check this solution.

C#
cmd.Parameters.AddWithValue("@user_id", 10);
cmd.Parameters.AddWithValue("@firstname", firstname);
cmd.Parameters.AddWithValue("@lastname", lastname);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@address1","");
cmd.Parameters.AddWithValue("@address2","");
cmd.Parameters.AddWithValue("@job_function", job_function);
cmd.Parameters.AddWithValue("@city", city);
cmd.Parameters.AddWithValue("@state", "");
cmd.Parameters.AddWithValue("@zip", "");
cmd.Parameters.AddWithValue("@country", country);
cmd.Parameters.AddWithValue("@user_active", "");
cmd.Parameters.AddWithValue("@user_intemail", "");
cmd.Parameters.AddWithValue("@user_added", DateTime.Now.Date);
cmd.Parameters.AddWithValue("@user_last_logged_in", "");
cmd.Parameters.AddWithValue("@user_updated", "");
cmd.Parameters.AddWithValue("@user_group", "");
cmd.Parameters.AddWithValue("@user_comment", "");
cmd.Parameters.AddWithValue("@user_title", title);
cmd.Parameters.AddWithValue("@user_password_temp", "");
cmd.Parameters.AddWithValue("@is_login", "");
cmd.Parameters.AddWithValue("@paraIVtype", "");
cmd.Parameters.AddWithValue("@activationdt",DateTime.Now.Date);
cmd.Parameters.AddWithValue("@expirydate",DateTime.Now.AddYears(10));
cmd.Parameters.AddWithValue("@company_name", company);
 
Share this answer
 
Sir, you call Any storProcedure in .Cs Page yors storProcedure and .Cs Page You right those parameter you right in a Double Code is every time is same
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900