[RESOLVED] My.Application.Info.DirectoryPath
What am I doing wrong ?
Code:
This is working
dbSource = "Data Source = C:\test\AddressBook.mdb;Jet OLEDB:Database Password=123;"
This is not
dbSource = "Data Source= (My.Application.Info.DirectoryPath & "\AddressBook.mdb;Jet OLEDB:Database Password=123;")
What ever I chang it is not working .
The file is Adressbook.mdb
Password = 123
and the file is here
My.Application.Info.DirectoryPath
Re: My.Application.Info.DirectoryPath
either you mistyped it or you are get an error at design time because your quote don't match...
try something like this
dbSource = string.format("Data Source= ({0}\AddressBook.mdb;Jet OLEDB:Database Password=123;",My.Application.Info.DirectoryPath)
or you could use IO.Path.combine(My.Application.Info.DirectoryPath,"\AddressBook.mdb") to create the full path first
Re: My.Application.Info.DirectoryPath
Re: My.Application.Info.DirectoryPath
Quote:
Originally Posted by
BASSIES
What am I doing wrong ?
Code:
This is working
dbSource = "Data Source = C:\test\AddressBook.mdb;Jet OLEDB:Database Password=123;"
This is not
dbSource = "Data Source= (My.Application.Info.DirectoryPath & "\AddressBook.mdb;Jet OLEDB:Database Password=123;")
What ever I chang it is not working .
The file is Adressbook.mdb
Password = 123
and the file is here
My.Application.Info.DirectoryPath
not sure but think you missed a closing quote
Code:
dbSource = "Data Source= (My.Application.Info.DirectoryPath & "\AddressBook.mdb;Jet OLEDB:Database Password=123;")"
try that
Re: My.Application.Info.DirectoryPath
Nope ,
Here is the code that i have found , maybe that explainse my problem .
To open the file .
Code:
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim Sql As String
Try
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
''This is working
''dbSource = "Data Source = C:\test\AddressBook.mdb;Jet OLEDB:Database Password=123;"
'' This is not
dbSource = "Data Source = (My.Application.Info.DirectoryPath & "\AddressBook.mdb;Jet OLEDB:Database Password=123;")
con.ConnectionString = dbProvider & dbSource
con.Open()
Sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "AddressBook")
con.Close()
TextBox1.Text = ds.Tables("AddressBook").Rows(0).Item(3)
Catch ex As Exception
End Try
Re: My.Application.Info.DirectoryPath
not sure how that code even compiles.... you are missing a quote.
Re: My.Application.Info.DirectoryPath
Did you try my suggestion? it doesnt look like you made the change based on the code you just posted. I understand our problem.
You are missing a quote
try what I suggested please
Re: My.Application.Info.DirectoryPath
billboy , I tried that
But then i get a error on Adressbook , database en password they are not declared
I think You are correct there is missing a qoute or something
Re: My.Application.Info.DirectoryPath
me shakes his head and points to post #2
Re: My.Application.Info.DirectoryPath
Kebo ,
I tried that but it is not working.
I don't understand what You mean by that.
Re: My.Application.Info.DirectoryPath
The String.Format method will create a string for you from text and variables. In the following line....
Code:
dbSource = string.format("Data Source= ({0}\AddressBook.mdb;Jet OLEDBatabase Password=123;",My.Application.Info.DirectoryPath)
My.Application.Info.DirectoryPath is a variable that replaces the {0} in the beginning of the string
Code:
dim s as string = "vb.net"
dim s2 as string = String.Format("{0} is ok",s)
will result in
s2 = "vb.net is ok"
Did you try it?
Re: My.Application.Info.DirectoryPath
Please dont say things like "I tried it it dosnt work"
post what you tried, often times you may think you tried it correctly but made a mistake or were confused about something(trust me being new myself i have done that a thousand times)
so post your new code and we can see if mistakes were made
did you try kebos suggestion in post#2, that is a cleaner way of doing what you want and less prone to errors with quotes and such
again post the code you tried and the erro you get and where the error occurs
Re: My.Application.Info.DirectoryPath
Oke sorry,
Here is my latest try
Code:
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim Sql As String
Dim s As String = "My.Application.Info.DirectoryPath"
Dim s2 As String = String.Format("{0}\AddressBook.mdb;Jet OLEDBatabase Password=123;", s)
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = String.Format("Data Source= ({0}\AddressBook.mdb;Jet OLEDBatabase Password=123;", My.Application.Info.DirectoryPath)
con.ConnectionString = dbProvider & dbSource
con.Open()
Sql = "SELECT * FROM tblContacts"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "AddressBook")
con.Close()
TextBox1.Text = ds.Tables("AddressBook").Rows(0).Item(3)
I get a error now
Code:
Could not find installable ISAM file.
Re: My.Application.Info.DirectoryPath
In a connection string you use |DataDirectory| to represent the program folder.
Code:
Dim connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AddressBook.mdb;Jet OLEDB:Database Password=123"
As there is no 64-bit version of the Jet OLE DB provider, make sure that your project targets the x86 platform or it will not work on 64-bit systems.
Re: My.Application.Info.DirectoryPath
This is working , thanks You all for your help
Code:
dbSource = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AddressBook.mdb;Jet OLEDB:Database Password=123"
Re: My.Application.Info.DirectoryPath
great please rate and mark your thread as resolved :)