mercredi 6 avril 2016

I am getting an error at get property with error 'BusinessLayer.EmployeeBusinessLayer.Employees.get': not all code paths return a value

I am getting an error at get property that not all code paths return a value.

namespace BusinessLayer
    {
        class EmployeeBusinessLayer
        {
            public IEnumerable<Employee> Employees
            {
                get // Here i am getting an error that not all code paths return a value
                {
                    string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                    List<Employee> employees = new List<Employee>();
                    using (SqlConnection con = new SqlConnection(ConnectionString))
                    {
                        SqlCommand cmd = new SqlCommand("spGetEmployees", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        con.Open();
                        SqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            Employee employee = new Employee();
                            employee.Emp_Id = Convert.ToInt32(rdr["Emp_Id"]);
                            employee.Emp_Name = Convert.ToString(rdr["Emp_Name"]);
                            employee.Designation = Convert.ToString(rdr["Designation"]);
                            employee.City = Convert.ToString(rdr["City"]);
                            employee.State = Convert.ToString(rdr["State"]);
                            employee.Country = Convert.ToString(rdr["Country"]);

                            employees.Add(employee);
                        }
                    }
                }
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire