|
-
Nov 24th, 2014, 09:41 AM
#1
Thread Starter
New Member
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()
-
Nov 24th, 2014, 10:28 AM
#2
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
-
Nov 24th, 2014, 01:47 PM
#3
Thread Starter
New Member
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
-
Nov 25th, 2014, 04:55 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|