OleDbDataAdapter da2 = new OleDbDataAdapter("SELECT nazivMaterijala FROM popisMaterijala", con);
DataTable dt = new DataTable();
da2.Fill(dt);
BindingSource bndSource2 = new BindingSource();
bndSource2.DataSource = dt;
this.comboBox1.DataSource = bndSource2;
comboBox1.DisplayMember = "nazivMaterijala";
comboBox1.ValueMember = "nazivMaterijala";
使用这部分代码,我将表名放入组合框中
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(connectionString);
OleDbDataAdapter da2 = new OleDbDataAdapter("SELECT * FROM [" +this.comboBox1.SelectedValue.ToString() +"]", con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da2.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da2.Fill(dt);
this.dataGridView1.DataSource = dt;
}
从 combobox1 中选择某些内容后,它应该使用所选表中的数据填充 gridview,但无法使其工作
这是我尝试运行它时收到的消息:Microsoft Access 数据库引擎找不到输入表或查询“System.Data.DataRowView”。确保它存在并且其名称拼写正确。