2

I always failed to load DataGridView customers. They always freeze on record #8

I have a Customers class under my apps namespace like this

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; }
    }

And this is my code to add item to customersBindingSource in my DataGridView and I put in formLoad event

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();

If I'm trying with data less than 8 on customers table it always work, but when I add new customers more than 8 it's always freeze, customers forms doesn't show up. Are there's a limitation or something wrong with my code?

1 Answer 1

1

try like this way:

// 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;

hope it can help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.