How can I use ODBC in a Windows Form?

Torquinian 21 Reputation points
2025-06-03T09:48:40.8566667+00:00

I am using VS2022 and VB.

I have a Windows Forms project that currently Imports System.Data.sqlclient into each Form.

I want to gradually move away from sqlclient to odbc, and my idea is to do it one Windows Form at a time as I hope to be able to Import the relevant System.Data namespace as I alter each Form.

The problem that I am having is that when I replace Imports System.Data.SqlClient with Imports System.Data.ODBC I am informed that the import is un-necessary and the places in the code that accesses the database are shown as errors.

How can I use ODBC in my Windows Forms?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,889 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,416 Reputation points
    2025-06-03T10:19:25.4866667+00:00

    I am informed that the import is un-necessary and the places in the code that accesses the database are shown as errors.

    Just changing your namespace don't changes your data access code; you have to modify that as well and therefore you get the error messages.

    E.g. instead of SqlConnection you have to use OdbcConnection class, see

    https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc.odbcconnection?view=net-9.0-pp


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.