我正在尝试将存储过程listbox
中的员工数据加载到表单加载事件中,ID
并为每个事件分配一个图像。上面的代码是我迄今为止所拥有的。所以我在这里要做的是listview
用我的数据阅读器中的数据填充数据。
SqlConnection conn = new SqlConnection(
@"Data Source=MyPC\Test;Initial Catalog=TEST5;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT emp_first_name FROM Employees", conn);
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
listView1.Items.Clear();
while (dr.Read())
{
ListViewItem recs = new ListViewItem();
recs.Text = dr["dept_name"].ToString();
recs.Text = dr["emp_first_name"].ToString();
recs.Text = dr["emp_last_name"].ToString();
recs.Text = dr["emp_email"].ToString();
recs.Text = dr["emp_phone"].ToString();
recs.Text = dr["emp_position"].ToString();
recs.Text = dr["emp_address1"].ToString();
recs.Text = dr["emp_address2"].ToString();
recs.Text = dr["emp_city"].ToString();
recs.Text = dr["emp_state"].ToString();
recs.Text = dr["emp_postal_code"].ToString();
recs.Tag = dr["empId"].ToString();
recs.ImageIndex = 0;
listView1.Items.Add(recs);
}
先感谢您。