If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Connection String in VB 2008

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-11, 09:56
mustish1 mustish1 is offline
Registered User
 
Join Date: Jul 2006
Posts: 149
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 10:08.
Reply With Quote
  #2 (permalink)  
Old 09-19-11, 11:27
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 09-19-11, 11:58
mustish1 mustish1 is offline
Registered User
 
Join Date: Jul 2006
Posts: 149
Can you please give me an example
Reply With Quote
  #4 (permalink)  
Old 09-19-11, 12:08
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton

Last edited by healdem; 09-19-11 at 12:11.
Reply With Quote
  #5 (permalink)  
Old 09-19-11, 12:13
mustish1 mustish1 is offline
Registered User
 
Join Date: Jul 2006
Posts: 149
ok. Thanks
Reply With Quote
  #6 (permalink)  
Old 09-19-11, 12:13
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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.
__________________
oh yeah... documentation... I have heard of that.

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

Last edited by Teddy; 09-19-11 at 12:22.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On