Use of bindingNavigator

Asked

Viewed 212 times

1

I fill a dataGridView via SQL and filling a dataTable.

I’d like to associate a bindingNavigator eastward dataGridView.

I’m not getting it. 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’re in trouble on this line:

bindingNavigator1.BindingSource = dt;

That is, after the equals sign does not accept dt. What’s the mistake?

1 answer

1


On the estate BindingNavigator.BindingSource, inform a BindingSource:

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

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

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

// ....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.