所以我有两种形式。一个是包含交付列表框的主表单,其中数据从数据库加载。另一种形式是交付表单,当用户从列表框中选择交付时,其详细信息应显示在交付表单中。到目前为止,我已经设法加载数据并设法在我的交付表单中显示一些文本。但是,我无法让我的交付表单显示列表框中所选交付的数据。
这是我的一些代码:
private void FrmDelivery_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\visits.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT CustomerName, CustomerAddress, ArrivalTime FROM tblVisits", con);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.txtCustomerName.Text = sdr["CustomerName"].ToString();
this.txtCustomerAddress.Text = sdr["CustomerAddress"].ToString();
this.txtArrivalTime.Text = sdr["ArrivalTime"].ToString();
}
sdr.Close();
if (theDelivery != null)
{
txtCustomerName.Text = theDelivery.customerName;
txtCustomerAddress.Text = theDelivery.customerAddress;
txtArrivalTime.Text = theDelivery.arrivalTime;
}
}