我用数据库连接创建了一个简单的程序:
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
如何使目录动态化?那么,无论我在何处放置已发布的应用程序,它都会起作用吗?
答案 0 :(得分:0)
您可以将其设置为与应用程序相关,如 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")