0

When making a project in WPF C# (.NET 5.0), I wanted to use data from my database. I have a Microsoft Access file (2000-2003 compatible version, *.mdb), which I needed to use for my project.

After I added new source Add > new Item... > Data > DataSet and specified properly the database (the connection was tested successful), file DataSetProj.xsd has been created.

However, when I tried running the code, the following error occurred:

Error   CS1069: The type name 'OleDbDataAdapter' could not be found in the namespace 'System.Data.OleDb'. This type has been forwarded to assembly 'System.Data.OleDb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

When clicking the CS1069 hyperlink, this site opened (unfortunately, no specifics on the error were provided).

Trying to fix the error myself, I found System.Data.OleDb namespace documentation. Here's my interesting observation: The code automatically generated by DataSetProj.Designer.cs file had classes (supposedly defined in the namespace), like OleDbConnection, or OleDbDataAdapter. Funnily enough, this namespace mentions these classes, but it appears they are not part of the namespace (although this is official MS documentation). When I enter documentation of either of the classes, they are included in the System.Data.Ole.Db namespace. This is weird and super unclear (at least for me, junior dev) documentation.

I tried switching to .NET 4.8 Framework, use EF Core Power Tools by ErikEJ (unfortunately it doesn't work with Access *.mdb file). I could not find the answer to this problem anywhere, although it seems like many people would have such an issue.

How do I make it work?

KifoPL
  • 981
  • 7
  • 18

2 Answers2

2

I noticed that the namespace System.Data.OleDb referenced in OleDbDataAdapter class is located in System.Data.OleDb.dll Assembly. When googled the name of the assembly, I found this link. After downloading and installing the assembly (using NuGet Package Manager), the error was resolved.

I hope that other people having the same issue will have it fixed upon visiting this post.

KifoPL
  • 981
  • 7
  • 18
0

System.Data.OleDb is not part of .Net 5 but is available as part of the .Net Platform Extensions. See below link for more details on .Net Platform Extensions: What are .NET Platform Extensions on learn.microsoft.com?

If ok with exclusively targeting Microsoft Windows Platform, you can consider installing the windows compatibility pack which includes the OleDb dll as well (below link) or consider rewriting your code to avoid OleDb (ODCB or ADO maybe?): https://www.nuget.org/packages/Microsoft.Windows.Compatibility