vb.net 发布带有数据库的应用程序
我想为我的项目建立一个内置数据库,这就是我到目前为止所做的,我将 mdb 文件放在项目
C:\Users\Jedi Dioh\Documents\Visual Studio 2010\Projects\kuya jake\kuya jake\bin 中\调试\
我做了一些研究,这就是我现在所做的,
Public Module Module1
Public path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\"
Public source As String = "Data Source = " + path.Replace("file:\", "") + "JIMMY.MDB"
End Module
这是未发布时的形式
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/JIMMY.mdb"
con.ConnectionString = dbProvider & source
'alternative way of connection
'Dim fldr As String
'Environment is the user profile
'fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "/AddressBook.mdb"
'dbSource = "Data Source = " & fldr
con.Open()
sql = "select * from TURNING"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "RECORDS")
con.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "RECORDS"
,但当我运行发布时,我收到此错误
我不知道现在该怎么办
i want to have a built in database for my project this is what i did so far, i placed the mdb file inside the project
C:\Users\Jedi Dioh\Documents\Visual Studio 2010\Projects\kuya jake\kuya jake\bin\Debug\
i did some research this is what i did
Public Module Module1
Public path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\"
Public source As String = "Data Source = " + path.Replace("file:\", "") + "JIMMY.MDB"
End Module
now this is the form
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/JIMMY.mdb"
con.ConnectionString = dbProvider & source
'alternative way of connection
'Dim fldr As String
'Environment is the user profile
'fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "/AddressBook.mdb"
'dbSource = "Data Source = " & fldr
con.Open()
sql = "select * from TURNING"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "RECORDS")
con.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "RECORDS"
its fine when not published but when i run the published i get this error
i don't know what to do now
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两种选择,具体取决于您是否希望在更新应用程序时保留对数据库所做的更改。
如果您在更新应用程序时不关心数据库中的数据,则可以将其包含在项目中,并使用“内容的构建操作”和“始终复制”或“较新时复制”的“复制到输出目录”设置。
如果您确实关心数据库中的数据并且不希望在更新应用程序时覆盖它,那么您需要将其存储在众所周知的位置(即c:)并将对该位置的引用存储在您的申请。
You have two choices depending on whether you want changes that have been made to the database to preserved when you update the application or not.
If you do not care about the data in the database when you update the application, then you can include it in the project with a Build Action of Content and a Copy To Output Directory setting of Copy Always or Copy If Newer.
If you do care about the data in the database and don't want it to be overwritten when you update your application, then you need to store it in a well-known location (i.e. c:) and store the reference to that location in your application.