哦,请有人向我解释为什么会这样……
public List<EmployeeHeader> GetEmployees()
{
List<EmployeeHeader> eh = new List<EmployeeHeader>();
string query = "SELECT " +
" firstName, lastName " +
"FROM" +
" tbEmployee ";
DBConnect db = new DBConnect();
DataTable dt = new DataTable();
dt = db.getBD(query);
int CountRows = dt.Rows.Count;
EmployeeHeader emp = new EmployeeHeader();
for(int i = 0; i < CountRows; i++)
{
emp.firstName = dt.Rows[i]["firstName"].ToString();
emp.lastName = dt.Rows[i]["lastName"].ToString();
eh.Add(emp);
}
return eh;
这是课程:
public class EmployeeHeader
{
public string firstName { get; set;}
public string lastName {get; set;}
}
最终结果是……
<ArrayOfEmployeeHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.istec.pt/">
<EmployeeHeader>
<firstName>Hugo</firstName>
<lastName>Almeida</lastName>
</EmployeeHeader>
<EmployeeHeader>
<firstName>Hugo</firstName>
<lastName>Almeida</lastName>
</EmployeeHeader>
<EmployeeHeader>
<firstName>Hugo</firstName>
<lastName>Almeida</lastName>
</EmployeeHeader>
<EmployeeHeader>
<firstName>Hugo</firstName>
<lastName>Almeida</lastName>
</EmployeeHeader>
<EmployeeHeader>
<firstName>Hugo</firstName>
<lastName>Almeida</lastName>
</EmployeeHeader>
</ArrayOfEmployeeHeader>
永远是同一个名字!!!我已经一步一步地调试,正确的名字进入了列表,但最后......我得到了相同的名字!
可能是一个愚蠢的错误,但请有人为我指出吗?
谢谢你