Search code examples
c#winforms3-tier

C# - 3 Tier Architecture. Error says No overload for method name takes 0 arguments


I am using 3 tier architecture in my C# Window Form. The thing I want to do is, hide the button if the data is exists. Here are my codes.

Class File

public bool checkIfExists(Variables variables) { // BelPar
        SqlCommand check = new SqlCommand();
        check.Connection = dbcon.getcon();
        check.CommandType = CommandType.Text;
        check.CommandText = "SELECT * FROM tbl";
        SqlDataReader drCheck = check.ExecuteReader();
        if(drCheck.HasRows == true)
        {
            drCheck.Read();
            if (... && .. ||) // conditions where variables are being fetch
            {
                return false;
            }
        }
        drCheck.Close();
        return true;
}

Window Form

btn_save.Visible = !balpayrolldetails.checkIfExists(); // This is where I get the "No overload for method 'checkIfExists' takes 0 arguments.

Any help? Please leave or answer below. Thank you


Solution

  • To call a method, you need to call it by its exact name, which in this case is:

    checkIfExists(Variables variables);
    

    This tells us that to use this method, we need to pass it in an object of type Variables to be used in the method execution.

    Whichever types are outlined in the method signature must be provided to successfully call a method.

    You will need to update your call from

    btn_save.Visible = !balpayrolldetails.checkIfExists();
    

    to

    btn_save.Visible = !balpayrolldetails.checkIfExists(someVariablesOfTheExpectedType);