?
Solved

where do i define an oledbconnection in vb.net?

Posted on 2005-03-14
3
Medium Priority
?
801 Views
Last Modified: 2010-05-18
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
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 375 total points
ID: 13534289
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
 
LVL 10

Expert Comment

by:EBatista
ID: 13534404
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13539700
I gave you tghe complete answer, so why only a B?

What else did you need or want?

AW
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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