Solved

ASP.net 'OleDbConnection' is not defined.

Posted on 2010-11-22
4
394 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:murbro
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:murbro
ID: 34190310
thanks very much
0

Featured Post

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.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

10 Experts available now in Live!

Get 1:1 Help Now