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;
}