Click here to Skip to main content
16,015,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass an instantiation of the below class 'Filters' to a subroutine

C#
public class Filters       // found in namespace SQLClass
{
    public Filters()
   {
        FirstNameFilter = "";
        LastNameFilter = "";
        AddressFilter = "";
        CityFilter = "";
        ZipCodeFilter = "";
    }

    public string FirstNameFilter { get; set; }
    public string LastNameFilter { get; set; }
    public string AddressFilter { get; set; }
    public string CityFilter { get; set; }
    public string ZipCodeFilter { get; set; }
}


Below is my attempt to create an instantiation of the class and pass it to a subroutine:

C#
        private void FrmMain_Load(object sender, EventArgs e)
        {
            CenterToParent();
            Filters ListFilters = new SQLClass.Filters();
            PopulateListView(ListFilters, "Last Name/First Name/City/Address");
// The above line gets error "Argument 1: Cannot convert from 'SQLClass.Filters' to 'ListFilters'"
        }

private void PopulateListView(ListFilters>, string OrderBy)
// The above line gets error "The type or namespace name 'ListFilters' could not be found (are you missing a using directive or an assembly reference?)"
        {
            SQLDatabase MySQLClass = new SQLDatabase();

            string TheDatabase = "CustomerDB";
            string TheProcedure = "usp_GetCustomers";
            Dictionary<string, ParameterValues> TheParams = new Dictionary<string, ParameterValues>();

            ParameterValues values = new ParameterValues();

            values = new ParameterValues(); values.Value = ListFilters.FirstNameFilter; values.Direction = "Input"; 
// The above line gets error "The name 'ListFilters' does not exist in the current context"
TheParams.Add("@parmFirstName", values);
            values = new ParameterValues(); values.Value = ListFilters.LastNameFilter; values.Direction = "Input"; TheParams.Add("@parmLastName", values);
            values = new ParameterValues(); values.Value = ListFilters.AddressFilter; values.Direction = "Input"; TheParams.Add("@parmAddress", values);
            values = new ParameterValues(); values.Value = ListFilters.CityFilter; values.Direction = "Input"; TheParams.Add("@parmCity", values);
            values = new ParameterValues(); values.Value = ListFilters.ZipCodeFilter; values.Direction = "Input"; TheParams.Add("@parmZipCode", values);
            values = new ParameterValues(); values.Value = OrderBy; values.Direction = "Input"; TheParams.Add("@parmOrderBy", values);


What I have tried:

The error messages are listed as comments. I have tried various ways of coding. I imagine / hope answer is simple.
Posted
Updated 16-Feb-20 15:29pm

1 solution

First off, you have a class, or "type", called Filters.

You then create an instance of that type, calling it "ListFilters". By the way, you should use camelCase to name your variables, "listFilters".

You then try to pass that variable to a method that is expecting the first parameter of type ListFilters. It has nothing to do with what you called the variable. It does not have to be named "listFilters" or "ListFilters".

This line:
C#
private void PopulateListView(ListFilters>, string OrderBy)

is bad. The first parameter is not defined correctly. Every parameter needs to define a type that is expected in that position and the variable that's going to hold that data inside the method.

I think you're trying to do something like this:
C#
private void PopulateListView(Filters listFilters, string orderBy)
 
Share this answer
 
Comments
Member 14633063 17-Feb-20 1:03am    
You are right of course.
I didn't follow one of the basic rules of C#.
Thank you.
CPallini 17-Feb-20 4:22am    
5.

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