title: how to load selected data from database and display in textbox in another form
body: <p>so i have two forms. one is the main form which contains a listbox of deliveries, where data gets loaded from a database. the other form is the delivery form which when the user selects the delivery from the listbox, its details should get displayed in the delivery form.
  so far i have managed to load the data in and managed to get some text displayed in my deliveryform. however, i cannot get my deliveryform to display the data of the selected delivery from the list box.</p>
  
  <p>here is a bit of my code:</p>
  
  <pre><code>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;
  }
  }
  </code></pre>