[求助]关于ListView
我按书本里写了下面的代码,运行起来没有出错,但是为什么显示的数据为空,数据库里有数据。ListView的VIEW设为DETAIL。改了几天都改不了出来,请各位大侠帮一下忙,看一下,谢谢。
public Form2()
{
string strConnect = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + Application.StartupPath + "\\abman.MDB";
OleDbConnection conConnection = new OleDbConnection(strConnect);
InitializeComponent();
ListView lv = new ListView();
lv.Columns.Add("工员",60, HorizontalAlignment.Right);
lv.Columns.Add("姓名",60, HorizontalAlignment.Right);
OleDbDataReader reader;
string strCommand = "SELECT * FROM xyuser";
conConnection.Open();
OleDbCommand cmd = new OleDbCommand(strCommand, conConnection);
reader = cmd.ExecuteReader();
while ( reader.Read ( ))
{
ListViewItem li = new ListViewItem() ;
li.SubItems.Clear ( ) ;
li.SubItems[0].Text = reader["xyuserID"].ToString ( ) ;
li.SubItems.Add ( reader["xyusername"].ToString ( ) ) ;
lv.Items.Add(li);
}
reader.Close();
}
[此贴子已经被作者于2007-11-21 17:57:14编辑过]