Link to home
Start Free TrialLog in
Avatar of mj168
mj168

asked on

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)
        myConnection2.Open()
        Dim myReader2 As OleDbDataReader = myCommand2.ExecuteReader
        myConnection2.Close()
    End Sub
End Class
-------------------------------------------------------------------------------

How do you define OleDb properties, methods, etc in a class file?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to add an extra import:

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

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You shouldn't need to use full namespace path.  Just simply import the System.Data.OleDb namespace as carl_tawn originally indicated.
Avatar of mj168
mj168

ASKER

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

Generated an invalid charater error: '%'
Avatar of mj168

ASKER

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'

and

Dim myReader2 As OleDbDataReader = myCommand2.ExecuteReader

OleDBDataReader generated an 'OleDbDataReader is not defined' error.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial