哪个是将.mdb(数据库文件)文件添加到vb.net应用程序的更好方法? [英] Which is the better way to add .mdb(database file) file to vb.net application?

查看:79
本文介绍了哪个是将.mdb(数据库文件)文件添加到vb.net应用程序的更好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我是Vb.NET的新手,所以我的问题似乎很简单,但要善意澄清我的怀疑。



我想部署一个Windows应用程序,以便知道如何在部署过程中添加访问文件?



另一个疑问我有没有可能使用添加新数据源添加数据库并自己编写程序来创建我自己的数据集来访问数据?



提前感谢

解决方案

,因为您已创建了访问.mdb文件,并且您知道它所在的位置以便打开您的项目,然后转到添加新数据源>选择数据库按下一步>在那里你可以找到新的连接点击那>将有数据源你可以找到写的Microsoft Access数据库文件(OLE DB)它是不是有点击更改选择Microsoft Access数据库文件,然后按确定>选择数据库后,将有数据库文件名选项浏览并转到该位置并选择您创建和存储的.mdb文件,然后按确定>之后会有测试连接按下,如果没问题,那么按确定>并且会有连接字符串之后(Provider = Microsoft.Jet.OLEDB.4.0; Data Source =C:\ Users \DELL \Desktop \ dell lab \\\\\\\\\\\\\\\\\\\\\\\ \ customer.mdb)这个字符串并将其保存在记事本中并通过按取消关闭该框不要按下。



之后因为我是显示示例



在表单中双击按钮,代码窗口将打开



因为这是我的代码,用于显示你的优惠





进口System.Data.OleDb'这是因为这个因为它而毁灭可以使用访问数据库

进口System.Data



公共类Form2



Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click

Dim s As String

s = Provider = Microsoft.Jet。 OLEDB.4.0;数据源= C:\ Users \ DELL \\Desktop \ unde lab \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\打开()

MsgBox(成功数据库连接)

connection.Close()





End Sub

结束班级





这是你可以为你的数据库添加数据库的解决方案项目



i希望这将有助于你


  Dim  conn  As   OleDbConnection 
Dim sConnString 作为 字符串
Dim cmd As OleDbCommand
Dim da 作为 OleDbDataAdapter
Dim dt < span class =code-keyword>作为 DataTable

尝试
如果 Microsoft.VisualBasic.Right(Application.StartupPath, 1 )= < span class =code-string> \ 然后
sConnString = Provider = Microsoft.ACE.OLEDB.12.0; Data Source =& Application.StartupPath& trial.mdb; Persist Security Info = False;
Else
sConnString = Provider = Microsoft.ACE.OLEDB.12.0;数据来源=& Application.StartupPath& \trial.mdb; Persist Security Info = False;
结束 如果
conn = OleDbConnection(sConnString )
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text



简单你可以使用像此


Dear Sir,

I am new to Vb.NET so my question may seem to be simple but do kindly clarify my doubts.

I want to deploy a windows application so want to know how to add the access file in deployment process?

Another doubt i have that is it possible to add database using Add New Data Source and write program from scratch on my own for accessing the data by creating my own dataset?

Thanks in advance

解决方案

as you have created the access .mdb file and u know the location where it is so open your project and then go to the add new data source > select database press next > there u can find new connection click on that > there will be data source u can find Microsoft Access Database File (OLE DB) written there is it is not there click on change select Microsoft Access Database File and press ok > after selecting your database there will be option of database file name browse that and go to the place and select the .mdb file where u have created and stored and then press ok > after that there will be test connection press that if it is ok then press ok > and after there will be connection string like ( Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Users\DELL\Desktop\dell lab\cr\cr\bin\Debug\customer.mdb" ) this copy that string and save it in notepad and close the box by pressing cancel don't press next .

after that as i am showing the example

take a button in the form double click on that the code window will open

AS THIS IS MY CODE FOR SHOWING U THE EXAPMLE


Imports System.Data.OleDb ' THIS IS TO DECLARE BECAUSE IT BY THIS U CAN USE ACCESS DATABASE
Imports System.Data

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s =Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\DELL\Desktop\dell lab\cr\cr\bin\Debug\customer.mdb;
Dim connection As New OleDbConnection(s)
connection.Open()
MsgBox(sucess database connectes)
connection.Close()


End Sub
End Class


this is the solution u can add database to your project

i hope this will help u


Dim conn As New OleDbConnection
        Dim sConnString As String
        Dim cmd As New OleDbCommand
        Dim da As New OleDbDataAdapter
        Dim dt As New DataTable

        Try
            If Microsoft.VisualBasic.Right(Application.StartupPath, 1) = "\" Then
                sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "trial.mdb;Persist Security Info=False;"
            Else
                sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\trial.mdb;Persist Security Info=False;"
            End If
            conn = New OleDbConnection(sConnString)
            conn.Open()
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text


simple you can use like this


这篇关于哪个是将.mdb(数据库文件)文件添加到vb.net应用程序的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆