I have a project and it need to choose database list on Combobox and show it in Datagridview. Here is my code :
private void Form2_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + @"data source= D:\Database\đồ án\Đồ án.mdb");
DataTable dt = new DataTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter("Select * from Sheet1", con);
da.Fill(dt);
da.Dispose();
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "Tên đề tài";
comboBox1.ValueMember = "Mã đề tài";
}
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + @"data source= D:\Database\đồ án\Đồ án.mdb");
DataTable dt = new DataTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter("Select * from Sheet11 Where Mã đề tài = "+comboBox1.SelectedValue, con);
da.Fill(dt);
da.Dispose();
dataGridView1.DataSource = dt;
}
When I run this program and click on Combobox, it shows an error:
https://i.stack.imgur.com/C7DdZ.png
At first, I thought 2 sheets (tables) in database was not showing and didn't relationship but when I make it done and tried to start again, it shows an error again. How can I fix it ?