不幸的是LINQ不支持訪問數據庫。隨着工作你周圍可以使用Ado.net數據集從數據庫
//create the connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";
//create the database query
string query = "SELECT * FROM MyTable";
//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
//fill the DataTable
dAdapter.Fill(dTable);
拔出數據然後你可以使用LINQ到對象做你的查詢(即使我不建議你使用這種方法,因爲的表現不是很好)
var results = from myRow in dTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
請閱讀:http://stackoverflow.com/questions/295772/query-microsoft-access-mdb-database-using-linq-and-c – adatapost