Using the bindingNavigator

1

I fill in a dataGridView via SQL and fill in a dataTable .

I would like to associate a bindingNavigator with this dataGridView .

I can not. Follow the code.

string arquivo = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "Sistema_de_provas.accdb";
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + arquivo + ";Jet OLEDB:Database Password=; Persist Security Info=False;";
cn.Open();

OleDbCommand com = new OleDbCommand();
com.Connection = cn;
com.CommandText = "SELECT * FROM PROVAS";

OleDbDataReader dr = com.ExecuteReader(); 
DataTable dt = new DataTable();
dt.Load(dr);
dataGridView2.DataSource = dt;
bindingNavigator1.BindingSource = dt;
cn.Close();

You have a problem with this line:

bindingNavigator1.BindingSource = dt;

That is, after the equal sign does not accept dt . What is wrong?

    
asked by anonymous 17.10.2016 / 01:17

1 answer

1

On the property BindingNavigator.BindingSource , report a BindingSource :

// ...
DataTable dt = new DataTable();
BindingSource bs = new BindingSource();

dt.Load(dr);
bs.DataSource = dt;

dataGridView2.DataSource = bs;
bindingNavigator1.BindingSource = bs;

// ....
    
17.10.2016 / 01:30