在我的代碼中,我爲每個按鈕做了一個方法,例如我有雞肉和牛肉按鈕,他們有自己的方法,當我點擊拳頭時間的雞肉按鈕時裝載它的表單將會顯示在列表框中,但是當我在雞之後點擊牛肉按鈕時,它會向我顯示一個System.ArgumentException。 這將如何解決?System.Data.DataRowView我該如何解決
private void Chicken()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("select Chicken_Name,WithOrWithout_Name,Chicken_Price from Tbl_Add a full outer join tbl_Chicken b ON b.Chicken_ID = a.Chicken_ID full outer join Tbl_WithORWithot c ON a.WorWO_ID = c.WithOrWothout_ID ; ", connection))
{
DataTable tbl_Chicken = new DataTable();
adapter.Fill(tbl_Chicken);
lst_SHowdata.DisplayMember = "Chicken_Name";
lstSHowdata2.DisplayMember = "Chicken_Price";
lst_SHowdata.ValueMember = "Chicken_ID";
lst_SHowdata.ValueMember = "Beef_ID";
lst_SHowdata.DataSource = tbl_Chicken;
lstSHowdata2.DataSource = tbl_Chicken;
}
}
private void Beef()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("select Beef_Name,WithOrWithout_Name ,Beef_Price from Tbl_Add a full outer join Tbl_Beef b ON b.Beef_ID = a.Beef_ID full outer join Tbl_WithORWithot c ON a.WorWO_ID = c.WithOrWothout_ID ; ", connection))
{
DataTable tbl_Beef = new DataTable();
adapter.Fill(tbl_Beef);
lst_SHowdata.DisplayMember = "Beef_Name";
lstSHowdata2.DisplayMember = "Beef_Price";
lst_SHowdata.ValueMember = "Beef_ID";
lst_SHowdata.ValueMember = "Chicken_ID";
lst_SHowdata.DataSource = tbl_Beef;
lstSHowdata2.DataSource = tbl_Beef;
}
}
private void button1_Click(object sender, EventArgs e)
{
Chicken();
}
private void button2_Click(object sender, EventArgs e)
{
Beef();
}
,我試圖通過使爲使異常
//lst_SHowdata.ValueMember = "Chicken_ID";
// lst_SHowdata.ValueMember = "Beef_ID";
還挺已經固定線路註釋,以解決它,但我需要點擊按鈕兩次,當我點擊它的第一次它會顯示在列表框System.Data.DataRowView。 如何解決它,並使其只顯示在第一次點擊?
「它給我一個System.ArgumentException」<---任何消息,與一起去? –
System.Windows.Forms.dll中發生未處理的「System.ArgumentException」類型異常。 附加信息:無法綁定到新值成員。 –
這是它顯示的異常時顯示的消息 –