Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2006
    Posts
    157

    Unanswered: Connection String in VB 2008

    I got syntax error: OleDbConnection not defined. Needs help Thanks.

    Imports System.Data
    Public Class Form1
    Dim myConn As OleDbConnection = New OleDbConnection();
    myConn.ConnectionString="Provider=Microsoft.Jet.OL EDB.4.0;Data Source=C:\vbcl\My1.acdb;"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim YesNo As DialogResult
    YesNo = MessageBox.Show("Do you want to save this file?", _
    "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    'Select YesNo
    End Sub
    End Class
    Last edited by mustish1; 09-19-11 at 11:08.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you need to define the connection inside a function or sub routines. AFAIK you cannot define the connection parameters in a global variable
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2006
    Posts
    157
    Can you please give me an example

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    public function afunction() as boolean

    myConn.ConnectionString="Provider=Microsoft.Jet.OL EDB.4.0;Data Source=C:\vbcl\My1.acdb;"
    end function

    dim myCnn as new conenction 'not to sure the declaration for this you may need to go with dim myconn as object

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    myConn.ConnectionString="Provider=Microsoft.Jet.OL EDB.4.0;Data Source=C:\vbcl\My1.acdb;"
    Dim YesNo As DialogResult
    YesNo = MessageBox.Show("Do you want to save this file?", _
    "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    'Select YesNo
    End Sub

    you may need to set the connection
    you may find it better to examine the connection object and see if it is valid, and if not initialise it correctly. the on line documentation is pretty good for this sort of problem
    Last edited by healdem; 09-19-11 at 13:11.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jul 2006
    Posts
    157
    ok. Thanks

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Check your import again. Also, make sure you don't have the "client framework" selected as your project version. For some bizarre reason projects will sometimes default to using the client framework instead of the full 3.x-4 framework. The client version is greatly pared down, I'm not sure if everything from System.Data is included or not.

    healdem is also correct. Once it stops complaining about not knowing what an OleDbConnection is, it will start complaining about you trying to manipulate private fields/members outside of a method or event. You'll probably want to set that connection string either in the form's constructor (winforms) or onload (asp.net)


    Noticed one more thing: I don't think VB likes you using semicolons as line delimiters. It's been a while since I switched to C#, but it could be complaining about that as well.
    Last edited by Teddy; 09-19-11 at 13:22.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •