我无法理解我的代码中的问题。我希望当用户选择一个表名时,它将显示在 datagridView 上。但我无法将我的数据发送到 dataTable。当我调试 dt 变量时为空。我缺少什么?
这是我到目前为止编写的代码:
public void ShowSelectedTable(string tableName, DataGridView grid, string dbFilePath)
{
try
{
OleDbConnection dbConn = new OleDbConnection();
dbConn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbFilePath;
dbConn.Open();
dbSet = new DataSet();
dbAdapt = new OleDbDataAdapter();
dbAdapt.SelectCommand = new OleDbCommand("Select * From " + tableName + ";", dbConn);
dbAdapt.Fill(dbSet);
dt = dbSet.Tables["TableName"];
grid.DataSource = dt;
}
catch(Exception ex)
{
MessageBox.Show("error");
}
}