Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

where do i define an oledbconnection in vb.net?

ive code this procedure to make a new connection, before i go any fuirther i want to get a prob cleared up.
my program is saying that oledbconnection not defined, where am i suppose to define it?

Private Sub MyDataConnection()
        'declares and instantiates a new OleDbConnection object
        Dim myConnection As New oledbconnection
        'sets the connection string to indicate a microsoft access
        'database as the specified path
        myConnection.connectionstring = "Provider=microsoft.jet.oledb.4.0;" & _
        "datasource=C:\Documents and Settings\Simon\My Documents\My Directory\Microsoft Certification\Projects\VB.Net Windows-Based Applications\dbFunctions.mdb"

    End Sub
0
scm0sml
Asked:
scm0sml
  • 2
1 Solution
 
Arthur_WoodCommented:
if this is your conplete code for this procedure :

Private Sub MyDataConnection()
        'declares and instantiates a new OleDbConnection object
        Dim myConnection As New oledbconnection
        'sets the connection string to indicate a microsoft access
        'database as the specified path
        myConnection.connectionstring = "Provider=microsoft.jet.oledb.4.0;" & _
        "datasource=C:\Documents and Settings\Simon\My Documents\My Directory\Microsoft Certification\Projects\VB.Net Windows-Based Applications\dbFunctions.mdb"

    End Sub
then the problem is that myConnection is only defined in this procedure, and NO WHERE else.  If you are trying to create the connection in this procedure, but ise it elsewhere in the code module, then move the line

Dim myConnection As New oledbconnection

outside the code for this procedure, and declare it at the MODULE level:


'declares and instantiates a new OleDbConnection object
        Dim myConnection As New oledbconnection

Private Sub MyDataConnection()

        'sets the connection string to indicate a microsoft access
        'database as the specified path
        myConnection.connectionstring = "Provider=microsoft.jet.oledb.4.0;" & _
        "datasource=C:\Documents and Settings\Simon\My Documents\My Directory\Microsoft Certification\Projects\VB.Net
Windows-Based Applications\dbFunctions.mdb"

         ' open the connection
         myConnection.Open
End Sub

AW
0
 
EBatistaCommented:
that is coz you have declared the connection within a procedure, so it will have only procedure scope, to make the connection "visible" to the rest of the class code declare it in the declaration seccion of the class.
0
 
Arthur_WoodCommented:
I gave you tghe complete answer, so why only a B?

What else did you need or want?

AW
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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