Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.net 'OleDbConnection' is not defined.

Posted on 2010-11-22
4
Medium Priority
?
410 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
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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