我是C#的新手,我正努力让数据从Access中显示在datagridview上。 所以我建立了一个数据库连接,它工作正常。但是加载数据的按钮出现了一个错误,似乎是说线路上存在问题" connection.Open();"
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select Title, Director * from MVDBtable";
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
connection.Close();
}
//show error message
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
答案 0 :(得分:0)
您必须使用正确的语法:
string query = "select Title, Director, * from MVDBtable";
或更可能:
string query = "select Title, Director from MVDBtable";