我有一个.ACCDB格式的数据库和一些表格。
我使用以下代码成功将其加载到OleDbDataReader中:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\\marcelo.accdb";
OleDbConnection conn = new OleDbConnection(connectionString);
string sql = "SELECT * FROM Clientes";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader;
reader = cmd.ExecuteReader();
我想将表“clientes”加载到数据表中。我该怎么办?
答案 0 :(得分:24)
string connString =
"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\\marcelo.accdb";
DataTable results = new DataTable();
using(OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Clientes", conn);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(results);
}