[英]Error CS0161: Not all code paths return a value
I have this error. 我有这个错误。 Can anyone tell me why?
谁能告诉我为什么? In TA.cs
在TA.cs
public class TA
{
public TA()
{
}
public static DataTable MergeTA()
{
DataTable myDT = new DataTable();
myDataTable.Columns.Add("AcadYear", typeof(string));
myDataTable.Columns.Add("NofGrp", typeof(System.Int16));
myDataTable.Columns.Add("LecHr", typeof(int));
...
...
...
DataRow myDR = myDT.NewRow();
myDataRow["AcadYear"] = "2009";
myDataRow["NoofGrp"] = "2";
myDataRow["LecHr"] = "1";
...
...
...
myDT.Rows.Add(myDR);
***return myDT;***
}
}
In Display.aspx.cs 在Display.aspx.cs中
...
...
...
string strConMethod = TA.MergeTA();
SqlConnection sqlConMethod = new SqlConnection(strConMethod);
DataTable haha = new DataTable();
haha = TA.MergeTA();
您需要在函数结束时返回DataTable:
return myDT;
You need to return a DataTable from your MergeTA method. 您需要从MergeTA方法返回DataTable。 Add this to the bottom:
将其添加到底部:
return(myDT);
You appear not to be returning myDT
at the end of MergeTA().
您似乎没有在
MergeTA().
结束时返回myDT
MergeTA().
That method is of type DataTable
, so all code paths through it must return a DataTable
. 该方法的类型为
DataTable
,因此通过它的所有代码路径都必须返回DataTable
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.