班级档案:
public class ServiceAccess
{
public DataTable GetAllShortCodes()
{
DataTable ShortCodeTable = new DataTable();
// logic to add data to Datatable
return ShortCodeTable;
}
}
代码背后:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = ServiceAccess.GetAllShortCodes();
}
很长一段时间都在做VB,但对C#来说是新手。我做错了什么?
答案 0 :(得分:3)
您正在调用GetAllShortCodes
,就像静态方法一样
您需要将其更改为此
var service = new ServiceAccess();
DataTable dt = service.GetAllShortCodes();
或将方法更改为静态方法
public static DataTable GetAllShortCodes()
{
DataTable ShortCodeTable = new DataTable();
// logic to add data to Datatable
return ShortCodeTable;
}