指向带有内置数据库的自我/创建应用程序的目录

发布于 2024-12-16 12:41:21 字数 687 浏览 0 评论 0原文

我制作了一个带有数据库连接的简单程序:

Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String

Dim ds As New DataSet 'holds table data
Dim da As OleDb.OleDbDataAdapter 'connection to database connectionobject
Dim sql As String

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/JIMMY.mdb"

con.Open()

sql = "select * from TURNING"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "RECORDS")

con.Close()

现在我从某人那里听说,为了制作带有内置数据库的应用程序,我应该将该文件放在项目中。

C:\Users\User\documents\visual studio 2010\Projects\myProject\JIMMY.MDB

如何使目录动态化?那么,无论我将已发布的应用程序放置在哪里,它都会起作用吗?

I made a simple program with a database connection:

Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String

Dim ds As New DataSet 'holds table data
Dim da As OleDb.OleDbDataAdapter 'connection to database connectionobject
Dim sql As String

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/JIMMY.mdb"

con.Open()

sql = "select * from TURNING"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "RECORDS")

con.Close()

Now I heard from someone that in order to make an application with a built in database, I should place the file inside the project.

C:\Users\User\documents\visual studio 2010\Projects\myProject\JIMMY.MDB

How do I make the directory dynamic? So, wherever I place the published application, will it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-12-23 12:41:21

您可以使其与应用程序相关,如如何:确定执行应用程序的路径

Dim path As String
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
dbSource = "Data Source = " + Path.Combine(path, "jimmy.mdb")

You can make it relative to the application, as explained in HOW TO: Determine the Executing Application's Path:

Dim path As String
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
dbSource = "Data Source = " + Path.Combine(path, "jimmy.mdb")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文