Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try this code for display data in high charts using dropdown value

What I have tried:

C#
[WebMethod]
public static string jqufunc(int year)
{

    string res = "[";
    ProjectdbEntities a = new ProjectdbEntities();

    var b = a.Catg_type;

    foreach (var c in b)
    {

        res += "'" + c.Catg_type1 + "',";
    }
    res = res.Substring(0, res.Length - 1);
    res += "]";

   


    //for program type
    var allprogs = a.Program_type;
    string res2 = "[";
    foreach (var pr in allprogs)
    {
        res2 += "{name: '" + pr.Prog_name + "',";


        string res3 = "[";
        var y = a.Year_info;
        foreach (var g in y)
        {
            res3 += "'" + g.year + "',";

            //for category type
            var allcats = a.Catg_type;

            res2 += "data:[";

            foreach (var ct in allcats)
            {
                res2 += a.Std_info.Where(t => t.Catg_id == ct.Catg_id && t.Prog_id == pr.Prog_id && t.year_id==g.year_id).Count().ToString().ToList() + ",";

            }

            res2 = res2.Substring(0, res2.Length - 1);
            res2 += "]";
            res2 += "},";



        }
        res2 = res2.Substring(0, res2.Length - 1);
        res2 += "]";
        //return (from c in a.Year_info where c.year_id == year select c).ToList();
        return res + "*" + res2;

    }
}


but this shows error

'WebApplication1.WebForm1.jqufunc(int)': not all code paths return a value
i already return a value

any solution
Posted
Updated 9-May-16 2:52am
v2

Your code - over-simplified:
C#
[WebMethod]
public static string jqufunc(int year)
{
    foreach (var pr in allprogs)
    {
        return res + "*" + res2;
    }
}


You can see that this code will return anything only if allprogs has at least one member - and that's not promised nowhere...
If there are no members the code will never enter the foreach and will not hit the return...
 
Share this answer
 
We dont know about the logic behind your code, seems lot of looping are there

the return keyword should be placed outside the loop since you are returning some value.

return the variable (res) at the last line of the function.

always follow this pattern
C#
public  ReturnType  MyMethod()
       {
            ReturnType  returnValue = default(ReturnType);
           //
           // Your Code (for loop or any )
           //
           return returnValue;
       }
 
Share this answer
 
v4
Comments
Philippe Mori 9-May-16 12:21pm    
And you need to initialize the return value for the case where the loop is empty...
Karthik_Mahalingam 9-May-16 12:39pm    
yes,updated.
Thanks Philippe

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900