Solved

ASP.net 'OleDbConnection' is not defined.

Posted on 2010-11-22
4
401 Views
Last Modified: 2012-05-10

Hi. In t6he following code I am getting the following error
'OleDbConnection' is not defined.      
Do I need to add a reference or something



    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


'// define a connection to the database
        Dim cn As New OleDbConnection(ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString)

        '// define the sql statement to execute
        Dim cmd As New OleDbCommand("SELECT * FROM [YourTable]", cn)

        Try

            '// open the connection
            cn.Open()

            '// execute the sql statement
            Using reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

                While reader.Read()
                    '// this loops through all of the returned records
                End While

            End Using

        Catch ex As Exception

        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try


    End Sub
0
Comment
Question by:Murray Brown
[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
4 Comments
 
LVL 5

Expert Comment

by:buraksarica
ID: 34188042
do you see   "System.Data.OleDb" listed in the using list at the top of your code? if not, please add. if it doesnt identify, reference System.Data assembly.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34188059
If you haven't already you need to add the following two lines at the very top of your code:

Imports System.Data
Imports System.Data.OleDb

You may also need:

Imports System.Configuration

and you may need to add a reference to the System.Configuration assembly. To do that right-click on the Solution Explorer and choose "Add Reference". Then, in the dialog that appears, scroll down the ".Net" tab until you find "System.Configuration". Select it then click "OK".
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 34189639
Did you check that the connection string is set it up proper on the web.config??

I try on this way and works find

 Dim cn As New OleDbConnection
cn.Connectionstring=ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString
0
 

Author Closing Comment

by:Murray Brown
ID: 34190310
thanks very much
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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