how to connect my data base in vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2007
Posts: 18
Reputation: apchidara is an unknown quantity at this point 
Solved Threads: 0
apchidara apchidara is offline Offline
Newbie Poster

how to connect my data base in vb.net

 
0
  #1
Aug 24th, 2007
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 ...
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

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

 
0
  #2
Aug 24th, 2007
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.
  1. con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\shassanzadeh\Desktop\Sara\extra\AddressBook.mdp"
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 18
Reputation: apchidara is an unknown quantity at this point 
Solved Threads: 0
apchidara apchidara is offline Offline
Newbie Poster

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

 
0
  #3
Aug 27th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

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

 
0
  #4
Aug 27th, 2007
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...
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 18
Reputation: apchidara is an unknown quantity at this point 
Solved Threads: 0
apchidara apchidara is offline Offline
Newbie Poster

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

 
0
  #5
Aug 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

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

 
0
  #6
Aug 27th, 2007
What message does the exception give you?
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 18
Reputation: apchidara is an unknown quantity at this point 
Solved Threads: 0
apchidara apchidara is offline Offline
Newbie Poster

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

 
0
  #7
Aug 27th, 2007
it says it cant find this file while I double checked and the path is 100%correct
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

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

 
0
  #8
Aug 27th, 2007
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.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

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

 
0
  #9
Aug 27th, 2007
Read this article and you can even download a working sample which uses Connection to Access DB through ASP. Click here
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 18
Reputation: apchidara is an unknown quantity at this point 
Solved Threads: 0
apchidara apchidara is offline Offline
Newbie Poster

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

 
0
  #10
Aug 28th, 2007
thankx hamrick it is solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC