简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM