Casey Crookston
Casey Crookston

Reputation: 13955

member <method> cannot be accessed with an instance reference; qualify it with a type name instead

Class File:

public class ServiceAccess
{
    public DataTable GetAllShortCodes()
    {
        DataTable ShortCodeTable = new DataTable();
        // logic to add data to Datatable
        return ShortCodeTable;
    }
}

Code Behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = ServiceAccess.GetAllShortCodes();
    }

Been doing VB for a long time, but new to C#. What am I doing wrong?

Upvotes: 1

Views: 1070

Answers (1)

Reza
Reza

Reputation: 19863

You are calling GetAllShortCodes like a static method

you need to change it to this

var service = new ServiceAccess();
DataTable dt = service.GetAllShortCodes();

or changing the method to a static method as

public static DataTable GetAllShortCodes()
{
    DataTable ShortCodeTable = new DataTable();
    // logic to add data to Datatable
    return ShortCodeTable;
}

Upvotes: 4

Related Questions