由于 BrowerList 输出结果都是最后一条记录,后来网上查到了
if (dRead.HasRows) {
List<Class_RejectQuery> BrowerList = new List<Class_RejectQuery>(); Class_RejectQuery listRow = new Class_RejectQuery(); while (dRead.Read()) { listRow.id=dRead.GetString(0); listRow.sn = dRead.GetInt32(1); listRow.times = dRead.GetInt32(2); listRow.cause = dRead.GetString(3); listRow.auditor = dRead.GetString(4); listRow.customer = dRead.GetString(5); listRow.department = Convert.IsDBNull (dRead [6])?"": dRead.GetString(6); listRow.targetPerson = dRead.GetString(7); listRow.recordName= Convert.IsDBNull (dRead[8] ) ? "" : dRead.GetString(8); listRow.auditDate = dRead.GetString(9); BrowerList.Add(listRow); } }
仅仅是位置不同而已,结果却相大不相同
1 if (dRead.HasRows) 2 { 3 List<Class_RejectQuery> BrowerList = new List<Class_RejectQuery>(); 4 5 while (dRead.Read()) 6 {
Class_RejectQuery listRow = new Class_RejectQuery(); 7 listRow.id=dRead.GetString(0); 8 listRow.sn = dRead.GetInt32(1); 9 listRow.times = dRead.GetInt32(2); 10 listRow.cause = dRead.GetString(3); 11 listRow.auditor = dRead.GetString(4); 12 listRow.customer = dRead.GetString(5); 13 listRow.department = Convert.IsDBNull (dRead [6])?"": dRead.GetString(6); 14 listRow.targetPerson = dRead.GetString(7); 15 listRow.recordName= Convert.IsDBNull (dRead[8] ) ? "" : dRead.GetString(8); 16 listRow.auditDate = dRead.GetString(9); 17 BrowerList.Add(listRow); 18 } 19 }
转自 https://blog.csdn.net/caluu/article/details/73321107