Solved

ASP.net 'OleDbConnection' is not defined.

Posted on 2010-11-22
4
399 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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