1
所以我有兩種形式。一個是包含傳遞列表框的主要表單,其中數據從數據庫加載。另一種形式是當用戶從列表框中選擇遞送時的遞送形式,其細節應當在遞送形式中顯示。 到目前爲止,我已經設法加載數據並設法讓我的交付表單中顯示一些文本。但是,我無法讓我的配送表單顯示所選配送的數據。如何從數據庫加載選定的數據並以另一種形式顯示在文本框中
這裏有點我的代碼:
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;
}
}
變化TheDelivery表單控件的修飾符屬性,例如。 theDelivery.txtCustomerName.Modifiers = Public ||如果(theDelivery!= null) { theDelivery.txtCustomerName.Text =「Abc」; theDelivery.txtCustomerAddress.Text =「Abc」; theDelivery.txtArrivalTime.Text =「---」 } – Pranav1688