Results 1 to 16 of 16

Thread: [RESOLVED] My.Application.Info.DirectoryPath

  1. #1

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    Resolved [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

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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 OLEDBatabase 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
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    Re: My.Application.Info.DirectoryPath

    Thanks , but no result

  4. #4
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: My.Application.Info.DirectoryPath

    Quote Originally Posted by BASSIES View Post
    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

  5. #5

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    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

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: My.Application.Info.DirectoryPath

    not sure how that code even compiles.... you are missing a quote.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    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

  8. #8

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    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

  9. #9
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: My.Application.Info.DirectoryPath

    me shakes his head and points to post #2
    Last edited by kebo; Apr 18th, 2013 at 07:29 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  10. #10

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    Re: My.Application.Info.DirectoryPath

    Kebo ,

    I tried that but it is not working.

    I don't understand what You mean by that.

  11. #11
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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?
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  12. #12
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    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

  13. #13

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    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.

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    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"

  16. #16
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: My.Application.Info.DirectoryPath

    great please rate and mark your thread as resolved

Posting Permissions

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



Click Here to Expand Forum to Full Width