2012-05-07 45 views
0

我很肯定這是我的數據綁定的問題,但我不確定問題究竟是什麼。使用mysql我得到的行顯示在我的數據集中,但在執行綁定後,沒有行顯示在我的datagridview中。數據集上的行數不同於datagridview上的行數

conn = new MySqlConnection("server=localhost;database=mydb;uid=user;password=pass"); 
conn.Open(); 

grid = new DataGridView(); 
grid.Dock = DockStyle.Fill; 
ds = new DataSet(); 

adpt = new MySqlDataAdapter("select * from test limit 6;", conn); 
adpt.Fill(ds); 
Debug.WriteLine("data set rows found " + ds.Tables[0].Rows.Count); 

binding = new BindingSource(); 
binding.DataSource = ds; 
grid.DataSource = binding; 
Debug.WriteLine("data grid rows found " + grid.Rows.Count); 

conn.Close(); 

Controls.Add(grid); 

調試打印輸出是6和0.有人知道我的問題在哪裏嗎?

在此先感謝!

回答

2

只是做

grid.DataSource = ds.Tables[0]; 
1

或..如果你想使用的BindingSource(比如過濾),設置

binding.DataSource = ds.Tables[0]; 
相關問題