2016-04-15 73 views
2

我總是無法加載DataGridView客戶。他們總是凍結記錄#8C#與MySQL添加數據綁定源停止在記錄#8

我有這樣

public class Customers 
    { 
     public string No { get; set; } 
     public string ID { get; set; } 
     public string NoSPU { get; set; } 
     public string Name { get; set; } 
     public string Telp { get; set; } 
     public string Kavling { get; set; } 
     public string Tipe { get; set; } 
     public string Pokok { get; set; } 
     public string Bunga { get; set; } 
    } 

下我的應用程序命名空間的客戶類,這是我的代碼在我的DataGridView添加項目customersBindingSource,我把在formLoad事件

string query = "select * from customer";   
      customersBindingSource.Clear(); 
      Int32 i = 0; 
      MySqlDataReader reader = dx.findQuery(query); 
      while (reader.Read()) 
      { 
       i++; 
       customersBindingSource.Add(new Customers() { 
        No = i.ToString(), 
        ID = reader.GetString("id"), 
        NoSPU = reader.GetString("nospu"), 
        Name = reader.GetString("nama"), 
        Telp = reader.GetString("telp"), 
        Kavling = reader.GetString("kavling"), 
        Tipe = reader.GetString("tipe") 
       }); 
       MessageBox.Show(i.ToString()+" OKE"); 
      } 
      reader.Close(); 

如果我在客戶表上嘗試使用小於8的數據,它總是有效,但是當我添加8個以上的新客戶時,它始終凍結,客戶表單不顯示。我的代碼有限制或有什麼問題嗎?

回答

1

嘗試像這樣:

// Create and populate the list of DemoCustomer objects 
// which will supply data to the DataGridView. 
List<DemoCustomer> customerList = new List<DemoCustomer>(); 
customerList.Add(DemoCustomer.CreateNewCustomer()); 
customerList.Add(DemoCustomer.CreateNewCustomer()); 
customerList.Add(DemoCustomer.CreateNewCustomer()); 

// Bind the list to the BindingSource. 
this.customersBindingSource.DataSource = customerList; 

希望它可以幫助你。