|
-
Dec 17th, 2002, 07:54 PM
#1
Thread Starter
Member
How do i do app.path in VB.NET
Hi all,
How can i use App.path in VB.NET.App gives error as name 'App' is not decalred.
what shall i do.
I tried to import system.windows.Forms.application
but i could not make it correct.
Pl give me a solution
Dim Conn As ADODB.Connection
Dim objword As Word.Application
Conn = New ADODB.Connection()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.path & "\testdb.mdb;Mode=Share Deny None"
Conn.Open()
Thanks.
-
Dec 17th, 2002, 08:11 PM
#2
PowerPoster
Try Application.StartupPath(), or something like that, it is in the Application namespace.
-
Dec 17th, 2002, 10:21 PM
#3
Member
this also works...
AppDomain.CurrentDomain.BaseDirectory
-
Dec 18th, 2002, 12:57 AM
#4
Sleep mode
many choices are there :
VB Code:
'''''''1
strAppPath = Application.StartupPath
''''''''2
Imports System.Reflection
mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
'''''''''3
Public Apath As String = System.Environment.CurrentDirectory
''''''''''4
Imports System.IO
Dim dir As Directory
dir.GetCurrentDirectory()
and many ways to do that.So pick whatever you like.
Pirate
-
Dec 18th, 2002, 11:15 AM
#5
Thread Starter
Member
Thanks>it works fine but facing new problem
Hi,
Thanks .It works well now but facing new problem.
When i try to run the program it could not find the database application path and gives an error
the error is:
'System.runtime.interopservices.comException'occured in MArana form.exe
additional inforamtion for error is:
pl check the path name and spelled correctly.
the code:
Imports System.IO
Imports System.Reflection
Imports System.Windows.Forms.Application
Imports System.Runtime.InteropServices.COMException
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mAppPath As String
mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
Dim Conn As ADODB.Connection
Dim objword As Word.Application
Conn = New ADODB.Connection()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mAppPath & "\testdb.mdb;Mode=Share Deny None"
Conn.Open()
thanks
-
Dec 18th, 2002, 11:50 AM
#6
Thread Starter
Member
where shall i store mdb file in VB.NET
I have stored my testdb.mdb file in maranaform folder. and sametime i stored in bin folder also.But i am facing same problem.
the error is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in MaranaForm.exe
Additional information: 'C:\ram\mortgage\MaranaForm\bin\MaranaForm.exe\testdb.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
the code is:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mAppPath As String
mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
Dim Conn As ADODB.Connection
Dim objword As Word.Application
Conn = New ADODB.Connection()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mAppPath & "\testdb.mdb;Mode=Share Deny None"
Conn.Open()
Please give me a solution.
Thanks.
-
Dec 18th, 2002, 12:54 PM
#7
PowerPoster
I am not one hundred percent sure, but try changing this:
"\testdb.mdb
to this:
@"\testdb.mdb
or
"\\testdb.mdb
You are using a backslash constant in your string. To stop all backslash constants from being read, you use the @ in front of the literal string. Or you can continue using backslash constants in your strings, and use the proper one, which is \\, for the backslash character.
-
Dec 18th, 2002, 12:55 PM
#8
PowerPoster
Oops, never mind, I thought I was in the C# forum...lol.
-
Dec 18th, 2002, 01:10 PM
#9
Member
Can I ask why you're trying to use ADO with .NET? You should be using ADO.NET with .NET
Instead of using COM Interop to access ADODB, use the System.Data.OleDb Namespace to access your Acesss file
-
Dec 18th, 2002, 01:55 PM
#10
Thread Starter
Member
HI,
I could not solve the same problem.I tried your idea.But facing same problem.
Please help me out.
Thanks.
-
Dec 18th, 2002, 02:51 PM
#11
Sleep mode
is your db file under the folder \bin ??
-
Dec 18th, 2002, 03:06 PM
#12
Sleep mode
yes it is
anyways, this line of code returns this "path and name of the exe of your proj
VB Code:
Dim mAppPath As String
mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
try this :
VB Code:
Dim mAppPath As String = (Path.GetFullPath & "\" & "myfile.mdb")
-
Dec 18th, 2002, 03:07 PM
#13
Thread Starter
Member
Yes I keep the mdb fils file in both bin folder and maranaform folder.
-
Dec 18th, 2002, 03:09 PM
#14
Sleep mode
I'm sorry I couldn't see that
-
Dec 18th, 2002, 03:16 PM
#15
Thread Starter
Member
Dim mAppPath As String = (Path.GetFullPath & "\" & "myfile.mdb")
Argument not specified for parameter'path' of 'public shared overloads function get fullPath(Path as String) as string'
I tried your idea that gives error on tooltip(Argument not specified for parameter'path' of 'public shared overloads function get fullPath(Path as String) as string').
-
Dec 18th, 2002, 03:27 PM
#16
VB Code:
Dim mAppPath As String = Path.Combine(Application.StartUpPath,"myfile.mdb")
-
Dec 18th, 2002, 03:35 PM
#17
Sleep mode
guess gives the same result as mine but seems clearer
-
Dec 18th, 2002, 04:06 PM
#18
Thread Starter
Member
Hi,
I tried path.combime.But it gives different error now.
An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set.
Imports System.Data
Imports System.Reflection
Imports System.Windows.Forms.Application
Imports System.Runtime.InteropServices.ExternalException
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sApppath As String
LblDate.Text = firstdate
Dim conn As ADODB.Connection
conn = New ADODB.Connection()
Dim objword As Word.Application
Dim path As Object
'sApppath = System.Reflection.Assembly.GetExecutingAssembly.Location
sApppath = System.Windows.Forms.Application.StartupPath
sApppath = path.CombineApplication.StartupPath, "Addressdb.mdb")
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source=" & sApppath & "\Addressdb.mdb;Mode=Share deny None"
conn.Open()
End Sub
-
Dec 18th, 2002, 06:07 PM
#19
VB Code:
Dim conn As ADODB.Connection
conn = New ADODB.Connection()
Dim objword As Word.Application
'I took out some unneeded stuff here
sApppath = IO.path.Combine(Application.StartupPath, "Addressdb.mdb") 'you forgot a ( at the start here
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source=" & sApppath & ";Mode=Share deny None" 'the database name is already in the sApppath varaible so no need for it at the end
conn.Open()
-
Dec 18th, 2002, 07:17 PM
#20
Thread Starter
Member
Hi,
Thanks.It Works fine.Thank you very much.
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
|