Click here to Skip to main content
14,641,834 members
Rate this:
Please Sign up or sign in to vote.
See more:
Good day everyone i am working on a loan application. i am using three usercontrols and one form. the usercontrols are(registrationform,userprofile,loan status). the registrationform usercontrol contains button,textboxs,picturebox and datetimepicker and the userprofile usercontrol consist of a datagridview that shows newly inserted data. please i want the datagridview to automatically update after the user inserts there data.

sometimes it gives me this error
There is no argument given that corresponds to the required formal parameter 'upa' of 'Registrationform.Registrationform(userprofile)' 

please i need full correction.

What I have tried:

usercontrol registrationform

public partial class Registrationform : UserControl
        userprofile up;
        public Registrationform(userprofile upa)
            up = upa;

            private void btnreg_Click(object sender, EventArgs e)
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = "INSERT INTO Registrationform([Employementnumber],[FullName],[Dateofbirth],[Gender],[Occupation],[Maritalstatus],[Email],[Department],[Position],[HomeAddress],[Phonenumber],[Nationality],[Stateoforigin],[image]) VALUES (@empno,@fullname,@dob,@gen,@occ,@ms,@email,@dept,@post,@haddress,@pno,@nation,@soo,@img)";

                    cmd.Parameters.AddWithValue("@empno", txtempno.Text);
                    cmd.Parameters.AddWithValue("@fullname", txtfullname.Text);
                    cmd.Parameters.AddWithValue("@dob", dob.Value);
                    cmd.Parameters.AddWithValue("@gen", gender);
                    cmd.Parameters.AddWithValue("@occ", txtoccupation.Text);
                    cmd.Parameters.AddWithValue("@email", txtemail.Text);
                    cmd.Parameters.AddWithValue("@dept", txtdept.Text);
                    cmd.Parameters.AddWithValue("@post", txtpost.Text);


usercontrol userprofile
 public void disp()
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from Registrationform";
            DataTable data = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            dtuserpro.DataSource = data;
Updated 30-May-19 20:25pm
Richard Deeming 31-May-19 8:48am
That code obviously won't compile. You've tried to declare an event handler inside the constructor. You're using variables that don't exist. You've got random words in the middle of the code. You're missing closing braces.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Add a default constructor to RegistrationForm that does NOT require a parameter.

Then figure out where you are calling the form without a parameter (if it's not "design time").

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100