Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Microsoft Access MDB Database using LINQ and C#

Tags:

c#

linq

ms-access

I have a *.MDB database file, and I am wondering if it is possible or recommended to work against it using LINQ in C#. I am also wondering what some simple examples would look like.

I don't know a lot about LINQ, but my requirements for this task are pretty simple (I believe). The user will be passing me a file path to Microsoft Access MDB database and I would like to use LINQ to add rows to one of the tables within the database.

like image 646
Matthew Ruston Avatar asked Nov 17 '08 15:11

Matthew Ruston


People also ask

How do I run a MDB query?

Open the action query in Design view. On the Design tab, in the Query Type group, click Select. On the Design tab, in the Results group, click Run.

What is LINQ in C# with example?

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.

Is LINQ better than SQL?

More importantly: when it comes to querying databases, LINQ is in most cases a significantly more productive querying language than SQL. Compared to SQL, LINQ is simpler, tidier, and higher-level.


2 Answers

What you want is a LINQ to ODBC provider, or a LINQ to JET/OLEDB provider.

Out of the box, MS doesn't make one. There may be a 3rd party who does.

like image 198
FlySwat Avatar answered Sep 30 '22 08:09

FlySwat


Actually I recently (today) discovered that you can access an Access database with LinqToSql. It must be in the 2002 or newer format, you will not be able to drag and drop the tables to your datacontext so either manually create the objects in your dbml or you can use SQL Server Migration for Access to move it to a sql server and then drag and drop all you want. When you want to actually create the context pass it an OleDbConnection. Use your standard Jet.OLEDB.4.0 connection string on the OleDbConnection and you are good to go. Not sure of the limitation this may incurr though. I just did a quick sample and did an OrderBy without issue.

like image 24
David Avatar answered Sep 30 '22 08:09

David