Solved

How do you use OleDb inside a class file?

Posted on 2010-11-29
7
338 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 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