Dear all, as always I am back with yet again a simple question.
I have developed an application in vb.net which has VB interface as front end and access 2003 as backend. The application path which I setup initially is :
Dim MyConn As ADODB.Connection MyConn = New ADODB.Connection MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Lensesdb.mdb;" MyConn.Open()
here the access file is refering to C drive however, I want it to be within Application folder so that when I create the application, the file should be installed and ran directly from the application directory and not from C drive.
I have added the file into the compilation and it created the application (exe) fine however when I install the program and run it, it asks for the C:\Lensesdb.mdb file (says its missing) whereas the application file is within application folder.
I have found few ways online:
Public Function App_Path() As String Return System.AppDomain.CurrentDomain.BaseDirectory() End Function
Private Function GetAppPath() As String Dim i As Integer Dim strAppPath As String strAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location() i = strAppPath.Length - 1 Do Until strAppPath.Substring(i, 1) = "\" i = i - 1 Loop strAppPath = strAppPath.Substring(0, i) Return strAppPath End Function
I did bring them into my coding but I don't know how to refer to my application path when I type
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Lensesdb.mdb;"
how can I declare the the path so that I don't have to manually put it into the C drive of destination pc each time I install the application.
I hope I made some sense here:D