无法隐式转换类型'类型'到'键入'错误但类型相同

时间:2015-10-19 16:01:34

标签: c# wcf

EmployeeService.EmployeeWcfClient client = new EmployeeService.EmployeeWcfClient();
EmployeeService.Employee newEmp = client.getEmployee(Convert.ToInt32(TextBox1.Text));

当我尝试运行此代码时,出现错误

  

无法隐式转换类型' Employee.EmployeeService.Employee'到' Employee.EmployeeService.Employee

我不明白这段代码有什么问题。 getEmployee方法是:

public Employee getEmployee(int id)
{ 
    Employee empOb = new Employee();
    string connection = ConfigurationManager.ConnectionStrings["DBMS"].ConnectionString;
    using(SqlConnection conn = new SqlConnection(connection))
    {
        SqlCommand cmd = new SqlCommand("retrieveEmp", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter para = new SqlParameter();
        para.ParameterName = "@id";
        para.Value = id;
        cmd.Parameters.Add(para);
        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            empOb.id = Convert.ToInt32(reader["ID"]);
            empOb.name = Convert.ToString(reader["name"]);
            empOb.gender = Convert.ToString(reader["gender"]);
            empOb.date = Convert.ToDateTime(reader["date"]);
        }
    }

    return empOb;
}

0 个答案:

没有答案