我有一个数据表,我可以从我的访问数据库中填充而没有问题,但我想在其中添加一个步骤:
private void button_Open_Click(object sender, EventArgs e)
{
var open = new OpenFileDialog
{
InitialDirectory = "c:\\",
Filter = @"Access Files (*.mdb)|*.mdb|All files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true,
Multiselect = false
};
open.ShowDialog();
if (string.IsNullOrEmpty(open.FileName)) return;
try
{
var con = new OleDbConnection();
con.ConnectionString = "Provider= microsoft.jet.oledb.4.0; data source = " + open.FileName;
con.Open();
var dt = new DataTable();
var da = new OleDbDataAdapter("select * from tblCustomerAccount", con);
da.Fill(dt);
dataGridView_AccessDatabase.DataSource = dt.DefaultView;
con.Close();
}
catch (OleDbException ex)
{
//get the error message if connection failed
MessageBox.Show("Error in connection ..." + ex.Message);
}
}
我想在其中添加一个用表名填充的组合框,然后在选择组合框后,填充数据表。
如何使用表名填充组合框?
谢谢!
答案 0 :(得分:2)
//
string[] restrictions = new string[4];
restrictions[3] = "Table";
con.Open();
DataTable tabls=con.GetSchema("Tables",restrictions);
返回表示表名列
的数据表您可以将此数据表绑定到组合框并将datamemebr设置为TABLE_NAME