Solved

How do you use OleDb inside a class file?

Posted on 2010-11-29
7
332 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
Comment Utility
You need to add an extra import:

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

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 84 total points
Comment Utility
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
Comment Utility
You shouldn't need to use full namespace path.  Just simply import the System.Data.OleDb namespace as carl_tawn originally indicated.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mj168
Comment Utility
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>

Generated an invalid charater error: '%'
0
 

Author Comment

by:mj168
Comment Utility
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
Comment Utility
>> 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
Comment Utility
"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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now