Solved

How do you use OleDb inside a class file?

Posted on 2010-11-29
7
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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