Access数据库教程
连接
采用OleDbConnection对c#教程象
代码 1
Private Function getAccessConnection() As OleDbConnectionDim dbConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Resources/mag.mdb;Persist Security Info=true"Dim dbConnection As OleDbConnection = New OleDbConnection(dbConnectionString)TrydbConnection.Open()Catch Ex As Exception'MsgBox(Err.Description)End TryReturn dbConnectionEnd Function代码 2private Sub fillDataGridView()Dim sqlStr As String = "select * from Table"Dim DataAdapter As New OleDbDataAdapterDim dataSet As New DataSetDim DataGridView As New DataGridViewDim dbConnection As OleDbConnection = getAccessConnection()If dbConnection.State.ToString = "Closed" ThenMsgBox(Chr(13) & " access 数据库连接失败 " & Chr(13), , "警告")Exit SubEnd IfDataAdapter.SelectCommand = New OleDbCommand(sqlStr,dbConnection)TryDataAdapter.Fill(dataSet,"Table")DataGridView.DataSource = dataSet.Tables("Table").DefaultViewCatch Ex As ExceptionMsgBox(Err.Description)FinallydataSet.DisposeDataAdapter.DisposedbConnection.ClosedbConnection.DisposeEnd TryEnd Sub
PS:
Access数据库文件,可以通过 My Project -> 资源 -> 添加资源 -> 添加python基础教程现有文件 这样的方式来添加
调试状态下,每次运行项目,Resources下面的数据库将会覆盖Debug下的数据库
本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:/sdlin/article/details/2192347
如果觉得《vb.net 如何连接Access数据库》对你有帮助,请点赞、收藏,并留下你的观点哦!