我有这段代码从数据库中检索数据,但我的问题是它只显示我的ListViewItem
. 这是代码:
private void patientLvw_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
cmd = new OleDbCommand("SELECT * FROM PATIENTS ORDER BY PATIENTS.PatientNo;", conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
String patientNo = ""; ;
String lastName = "";
String firstName = "";
String middleInitial = "";
String age = "";
String address = "";
String type = "";
String status = "";
if (!reader.IsDBNull(0))
{
patientNo = reader.GetInt32(0).ToString();
}
if (!reader.IsDBNull(1))
{
lastName = reader.GetString(1);
}
if (!reader.IsDBNull(2))
{
firstName = reader.GetString(2);
}
if (!reader.IsDBNull(3))
{
middleInitial = reader.GetString(3);
}
if (!reader.IsDBNull(4))
{
age = reader.GetInt32(4).ToString();
}
if (!reader.IsDBNull(5))
{
address = reader.GetString(5);
}
if (!reader.IsDBNull(6))
{
type = reader.GetString(6);
}
if (!reader.IsDBNull(7))
{
status = reader.GetBoolean(7).ToString();
}
ListViewItem lvi = new ListViewItem(patientNo);
e.Item.SubItems.Add(lastName);
e.Item.SubItems.Add(firstName);
e.Item.SubItems.Add(middleInitial + ".");
e.Item.SubItems.Add(age);
e.Item.SubItems.Add(address + ".");
e.Item.SubItems.Add(type);
e.Item.SubItems.Add(status);
e.Item = lvi;
}
}