winforms fill datagridview with mysql data

时间:2016-07-11 20:25:40

标签: c# mysql winforms datagridview

I have little problem with DataGridView when I try to render MySL data inside the grid.

First, I use this mysql class

Next, I create model classes with methods which hold a MySql query. In that class I am using DI to inject Db class in to the following:

public class Option
{
    private readonly Database db;

    public Option()
    {
        db = new Database();
    }

    public DataTable ListAll()
    {
          return db.query("SELECT * FROM options");      
    }
}

Next in the form class I try this ListAll method to bind and set in dataSource:

  private void MainWindow_Load(object sender, EventArgs e)
  {
            Options o = new Options();      
            BindingSource bind = new BindingSource();

            bind.DataSource = o.ListAll();  

            dataGridView1.DataSource = bind;          
  }

After build I get : enter image description here

Can someone show me what am I doing wrong here?

0 个答案:

没有答案