简体   繁体   中英

Datagridview only shows column name

I have a SQL database with multiple tables and I want to bind one of them to a DataGridView. I use this code : http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx#Y210 But my datagridview only show column names and does not draw any rows. Does anyone can help me ?

If you can see the correct column names but don't see the data, there could be one of these two problems (or both):

  1. Your query returns nothing (check in your database manager if there are some data when you execute the query)
  2. Your table(s) in the database is empty therefore there is nothing to return.

EDIT: Have you tried switching these two statements?

Form1_Load(object sender, System.EventArgs e) 
{ 
       GetData("select * from Customers"); 
       dataGridView1.DataSource = bindingSource1; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM