-2

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

mark333...333...333
  • 1,270
  • 1
  • 11
  • 26
  • The error says it already. You need a parameter (of type Variables) for the function checkIfExists – JustAPup Jan 11 '16 at 20:31
  • Of course, the checkIfExists wants a parameter. Look at your method definition _public bool checkIfExists(**Variables variables**)_ You don't pass a Variables argument – Steve Jan 11 '16 at 20:31
  • To simply support calling parameter-less, you can change the signature to `checkIfExists(Variables variables=null)` – Reza Aghaei Jan 11 '16 at 20:34
  • By the way it has nothing to do with 3-tier and it's better to remove it from title, and remove the tag :) – Reza Aghaei Jan 11 '16 at 20:50

2 Answers2

2

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);
Matt Hensley
  • 908
  • 8
  • 18
1

Having the method signature:

public bool checkIfExists(Variables variables)

It should be called by passing an object of type Variables to the method:

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

But if it's acceptable for you to call the method parameter-less and your method is written in a way that can tolerate having variables with null value, you can change the signature to this:

public bool checkIfExists(Variables variables=null)

And then you can call it this way:

btn_save.Visible = !balpayrolldetails.checkIfExists();
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398