Lesley Peters
Lesley Peters

Reputation: 409

asp.net use class in app_code folder

the index page I use is index.aspx and the c# class is called index.aspx.cs.

In the app_code folder I have another folder called "database" and within that folder is a .cs file called Query.cs

Now in the index.aspx.cs file I want to call the Query.cs class with the following code:

private Query query = new Query();

but it can't find Query.

What can I do?

Upvotes: 0

Views: 1460

Answers (1)

Vijay Kumbhoje
Vijay Kumbhoje

Reputation: 1441

See Below Example

Your App_Code Class File like below

public class Query
{
    public Datatable SelectData()
    {
        // Query Goes Here..
    }
}

Your index.aspx.cs file will be

//Create Object of Class
Query query = new Query();
Datatable dt = query.SelectData();
//Here Datatable is just considered for example

If you are calling class from another project you need give reference to that project.

Most of the times Access Modifiers are the issues in calling class members.

Upvotes: 2

Related Questions