Results 1 to 4 of 4

Thread: Retrieiving data from a database without having to put the file directory (REQ)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Retrieiving data from a database without having to put the file directory (REQ)

    Hello
    So basically I'm using a database to store all my data but whenever I access the database I have to put the file directory (see code below). This is going to be a problem as this is a college project, and my teacher/exam board will be trying out the system and because of each computer having different disk drive letters it will not work on other computers. I'm just wondering if there is a way for my to save the database in the project folder and the project to detect where it is no matter the file directory.

    Thanks to anyone who can help

    Code i'm using currently to add to a file -
    Dim strSQL As String
    Dim objCmd As New OleDbCommand
    strSQL = "INSERT INTO tblUsers(FirstName,Surname, userName, userPassword, userPosition) "
    strSQL = strSQL & "VALUES('" & (Firstname) & "', '" & (Surname) & "','" & (Username) & "', '" & (Password) & "', '" & (Position) & "');"
    Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=FILEDIRECTORY")
    Dim myConnection As OleDbConnection = New OleDbConnection
    Con.Open()
    objCmd = New OleDbCommand(strSQL, Con)
    objCmd.ExecuteNonQuery()
    Con.Close()

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Retrieiving data from a database without having to put the file directory (REQ)

    You have a few choices the easiest is if your database is always going to be in the same directory as your application you can do this -

    - You will need to import both - System.Reflection & System.IO

    Code:
    Dim location = Assembly.GetExecutingAssembly().Location
    Dim appPath = Path.GetDirectoryName(location)
    This will give you the path of your application!
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Re: Retrieiving data from a database without having to put the file directory (REQ)

    Ahh thank you very much, all I had to do from there was to add the database file name which won't change to the string from the location, your a life saver

  4. #4
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Retrieiving data from a database without having to put the file directory (REQ)

    no problem remember to mark your thread as resolved
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



Tags for this Thread

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