Search code examples
vb.netms-accessoledb

OleDbConnection not reconized in VB.NET


When I try to use OLeDBConnection or OleDBDataAdapter, it is not getting reconized by the project

I have Already imported the 'System.Data.OleDB'

System.Data.OleDB Imported

Error with the only options that I have to use with the OleDB

The type 'OleDBConnection' is not defined

What can I do to fix that and use the objects OleDbDataAdapter and OleDbConnection?


Solution

  • OLE DB only works on Windows, so it is not part of .NET Core, which is cross-platform. .NET 5.0 is .NET Core. .NET Framework will not be developed beyond version 4.8, so 5.0 onwards is the only .NET, hence the dropping of the "Core" suffix.

    As is always the case, no matter what type you're using or framework you're targeting, if you want to use a type then you need to reference the assembly that that type is declared in. Importing a namespace is NOT the same thing as referencing an assembly. Read this for more information on that.

    In .NET Core projects, you reference an assembly by adding the appropriate NuGet package. If you had read the documentation for the OleDbConnection class (here is the Australian version) then you'd have seen that it is declared in the System.Data.OleDb.dll assembly. All you need to do is add the System.Data.OleDb NuGet package to your project and you're away.

    If you're going to be using .NET 5.0 or any other version of .NET Core then you need to know about NuGet and how to find and add packages. If you don't know that already, stop what you're doing and spend the time to learn.