943,793 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3990
  • VB.NET RSS
Aug 24th, 2007
0

how to connect my data base in vb.net

Expand Post »
hi all:
I am a newbie , trying to connect my access to vb.net express edition I wrote the following code:

Imports System.Data
Public Class Form1

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim con As OleDb.OleDbConnection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0 ; Data Source = "C:\Documents and Settings\shassanzadeh\Desktop\Sara\extra\AddressBook.mdp"

End Sub
End Class


but the compiler gives me error for this line:
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0 ; Data Source = "C:\Documents and and Settings\shassanzadeh\Desktop\Sara\extra\AddressBook.mdp"


the erros says:Character constant must contain exactly one character.
can you guys help me ...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apchidara is offline Offline
18 posts
since Aug 2007
Aug 24th, 2007
0

Re: how to connect my data base in vb.net

You don't need to surround the database path in quotes inside a connection string. The key/value pairs are all delimited. It should look like this instead.
VB.NET Syntax (Toggle Plain Text)
  1. con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\shassanzadeh\Desktop\Sara\extra\AddressBook.mdp"
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

thanks hamrick
I did that now I have this code :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'seting the data connection
Dim sql As String
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\shassanzadeh\Desktop\Sara\extra\AddressBook.mdp"
'setting the data Adaptor and Data set

con.Open()
Sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(Sql, con)
MsgBox("connection open")
con.Close()
MsgBox("connection close")



End Sub

and no syntex error but while I compile it doesnt show any thing and after that I get this error"OleDbException was unhandled "and it poits to a yellow line on con.open()
well according to this link because I am using express edition , I should set my project refrences to System.Xml.dll but here there is no such thing it is only system.xml what do you think I should do?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apchidara is offline Offline
18 posts
since Aug 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

Quote ...
because I am using express edition , I should set my project refrences to System.Xml.dll but here there is no such thing it is only system.xml
System.Xml and System.Xml.dll are the same thing in the reference picker. But that reference should have been added when you made a windows forms project...
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

i changed that but still it gives errors on the line con.open()
I redo it again also I enclude at the top system.Xml but still it doesnt work.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apchidara is offline Offline
18 posts
since Aug 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

What message does the exception give you?
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

it says it cant find this file while I double checked and the path is 100%correct
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apchidara is offline Offline
18 posts
since Aug 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

Put it somewhere else without all of the extra nesting, like C:\. Make sure that the extension is right. If this is access, it should be *.mdb, not *.mdp, I think. When it tells you it can't find the file, it can't find the file. That means the connection string is wrong somehow.
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 27th, 2007
0

Re: how to connect my data base in vb.net

Read this article and you can even download a working sample which uses Connection to Access DB through ASP. Click here
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Aug 28th, 2007
0

Re: how to connect my data base in vb.net

thankx hamrick it is solved
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apchidara is offline Offline
18 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to load specific data into a texbox...
Next Thread in VB.NET Forum Timeline: 2-tier softwares





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC