How do you use OleDb inside a class file?

I have a class file using VB in an ASP.Net website. In that file there is a subroutine that will delete a record from a table in the database. The problem that I am having is that OleDb methods and properties generate the message below:

"OleDb...... is not defiened"

The class file code is below.

<%@ Import Namespace="System.Data" %>

Public Class Class2
    Sub RemoveTutorFromAllQueues()
        Dim mySelectQuery2 As String = ""

        Dim myConnectionString2 As String = ""
        Dim myConnection2 As New OleDbConnection(myConnectionString2)
        Dim myCommand2 As New OleDbCommand(mySelectQuery2, myConnection2)
        Dim myReader2 As OleDbDataReader = myCommand2.ExecuteReader
    End Sub
End Class

How do you define OleDb properties, methods, etc in a class file?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
add namespace System.Data.OleDb and try use full namespace path:

Dim myConnection2 As New System.Data.OleDb.OleDbConnection(myConnectionString2)
Dim myCommand2 As New System.Data.OleDb.OleDbConnection(mySelectQuery2, myConnection2)
Carl TawnSystems and Integration DeveloperCommented:
You need to add an extra import:

<%@ Import Namespace="System.Data.OleDb" %>

You shouldn't need to use full namespace path.  Just simply import the System.Data.OleDb namespace as carl_tawn originally indicated.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

mj168Author Commented:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>

Generated an invalid charater error: '%'
mj168Author Commented:
As for the other suggested method

Dim myCommand2 As New System.Data.OleDb.OleDbConnection(mySelectQuery2, myConnection2)

myCommand2 generated an error: 'no accessible New accepts this number of arguments'


Dim myReader2 As OleDbDataReader = myCommand2.ExecuteReader

OleDBDataReader generated an 'OleDbDataReader is not defined' error.
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
>> Dim myCommand2 As New System.Data.OleDb.OleDbConnection(mySelectQuery2, myConnection2)

That's supposed to be creating a Command, not a Connection. So should say:

Dim myCommand2 As New System.Data.OleDb.OleDbCommand(mySelectQuery2, myConnection2)

P1ST0LPETEConnect With a Mentor Commented:
"Generated an invalid charater error: '%'"

At the very top of your VB code behind, you should have:

Imports System.Data
Imports System.Data.OleDb

You do not want to use "<%@ Import Namespace="System.Data" %>" in code behind, as <% %> are used only in the asp markup side, not the code behind.
All Courses

From novice to tech pro — start learning today.