• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

ASP.net 'OleDbConnection' is not defined.

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)


            '// open the connection

            '// 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

            If cn.State <> ConnectionState.Closed Then
            End If
        End Try

    End Sub
Murray Brown
Murray Brown
1 Solution
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.
Carl TawnSystems and Integration DeveloperCommented:
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".
Jesus RodriguezIT ManagerCommented:
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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now