Solved

How do you use OleDb inside a class file?

Posted on 2010-11-29
7
333 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:mj168
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34229880
You need to add an extra import:

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

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 84 total points
ID: 34229899
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)
0
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34230206
You shouldn't need to use full namespace path.  Just simply import the System.Data.OleDb namespace as carl_tawn originally indicated.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:mj168
ID: 34230219
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>

Generated an invalid charater error: '%'
0
 

Author Comment

by:mj168
ID: 34230287
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.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 83 total points
ID: 34230301
>> 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)


0
 
LVL 10

Assisted Solution

by:P1ST0LPETE
P1ST0LPETE earned 83 total points
ID: 34230553
"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.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question