+ Reply to Thread
Results 1 to 2 of 2

Thread: Error : Not all code paths return a value

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    31

    Error : Not all code paths return a value

    I am using the below method , but i keep getting errors :
    Code:
    [WebMethod]
    public static LoadCitiesByState(string state)
    {
            DataTable table = SharedDataAccess.GetItems(state);
            List<string> items = new List<string>();
    
            foreach (DataRow row in table.Rows)
            {
                items.Add(row[0].ToString());
            }
            return items;
    
       }

  2. #2
    You need to specify the type of the variable you're returning:
    Code:
    public static List<string> LoadItemsByState(string state)
    Here is the full code :
    Code:
    public static List<string> LoadItemsByState(string state)
    {
        List<string> items = new List<string>();
        try 
        {
            DataTable table = SharedDataAccess.GetItems(state);
        } 
        catch
        {
            //exception here
        }
        foreach (DataRow row in table.Rows)
        {
            items.Add(row[0].ToString());
        }
        return cities;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts