Error CS0161: Not all code paths return a value

I have this error. Can anyone tell me why? In 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

...
...
...
string strConMethod = TA.MergeTA();
        SqlConnection sqlConMethod = new SqlConnection(strConMethod);
        DataTable haha = new DataTable();
        haha = TA.MergeTA();

      

+2


source to share


3 answers


You need to return DataTable from your MergeTA method. Add this to the bottom:



return(myDT);

      

+3


source


You need to return the DataTable at the end of your function:



return myDT;

      

+7


source


You don't seem to come back myDT

at the endMergeTA().

This method is of type DataTable

, so all code paths through it must return DataTable

.

0


source







All Articles