0

I am working in C#.

I have a connection string and I am fetching the details

class CustomerSummaries
{
    SqlConnection conn = new SqlConnection();

    public IEnumerable<T> GetAll()
    {
        try
        {
            SqlCommand cmd = new SqlCommand("GetAll", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlDataReader sdr;
            conn.Open();
            sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                if (sdr.IsDBNull(sdr.GetOrdinal("ContactName")) != true)
                {
                    sdr["ContactName"].ToString();
                }
            }
        }
        catch (Exception ex)
        {
            throw;
            //lblErrorMsg.Visible = true;
            //lblErrorMsg.Text += "<br><b>getProjectLead_Error: </b> " + ex.Message;
        }
        finally
        {
            conn.Close();
        }
    } 
}

I am getting an error that says Not all code path return a value, how could fix my code?

1 Answer 1

2

Your function declaration says you're going to return an IEnumerable<T>, but there is no return statement.

Furthermore, T is not a data type. I think you're going to have a bad time with that.

I also notice that sdr["ContactName"].ToString(); doesn't really do anything--it doesn't modify the column value because it's a function, not a method, and you're not assigning the result of the function to a variable to do something further with it.

Sign up to request clarification or add additional context in comments.

3 Comments

I can't tell you what you should be doing, only you know that. Ask a new question, stating what you want to accomplish, and provide enough code so we can understand the context. What kind of list do you want to return from your function?
Good point! IEnumerable here is my controller:public class CustomerSummaryController : Controller { // // GET: /CustomerSummary/ private CustomerSummaries _customerSummaries = new CustomerSummaries(); public ViewResult Index() { IEnumerable<CustomerSummary> summaries = _customerSummaries.GetAll(); return View(summaries); } }
You should ask a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.