Before introducing VB.NET Access database connection to everyone in detail, let everyone understand the introduction of VB.NET first, and then introduce VB.NET Access database connection comprehensively.
Visual Basic.NET evolved from the Visual Basic language vb.net tutorial
, Is a language designed to efficiently generate type-safe and object-oriented applications. Visual Basic allows developers to develop programs for Windows, Web, and mobile devices. Like all languages oriented to the Microsoft .NET Framework, programs written in Visual Basic have the advantages of security and language interoperability. This c# tutorial on behalf of Visual Basic continues the tradition of providing you with a simple and fast way to create applications based on the .NET Framework.
Introduction to VB.NET
VB.NET is Microsoft's latest platform technology and a language of .netframeworkSDK. There is no difference in function between VB.NET and VC#.NET. The executable file generated after compilation is called Assembly, that is, assembly. The version number of VB.net is VB7.0, and its python basic tutorial operation is built on CLR (CommonLanguageRuntime) and MSIL (MicrosoftIntermediateLanguage) virtual machines. In fact, its mechanism is similar to Java.
VB.NET Access database connection
Use OleDbConnection object
Private Function getAccessConnection() As OleDbConnection
Dim 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)
Try
dbConnection.Open()
Catch Ex As Exception
’MsgBox(Err.Description)
End Try
Return dbConnection
End Function
private Sub fillDataGridView()
Dim sqlStr As String = "select * from Table"
Dim DataAdapter As New OleDbDataAdapter
Dim dataSet As New DataSet
Dim DataGridView As New DataGridView
Dim dbConnection As OleDbConnection = getAccessConnection()
If dbConnection.State.ToString = "Closed" Then
MsgBox(Chr(13) & " access 数据库连接失败 " & Chr(13), , "警告")
Exit Sub
End If
DataAdapter.SelectCommand = New OleDbCommand(sqlStr,dbConnection)
Try
DataAdapter.Fill(dataSet,"Table")
DataGridView.DataSource = dataSet.Tables("Table").DefaultView
Catch Ex As Exception
MsgBox(Err.Description)
Finally
dataSet.Dispose
DataAdapter.Dispose
dbConnection.Close
dbConnection.Dispose
End Try
End Sub
The VB.NET Access database file can be added in the debugging state through My Project -> Resources -> Add Resource -> Add Existing File. Each time the project is run, the database under Resources will overwrite the database under Debug.
Label:
Articles on this site are original or translated except for reprinting. Any form of reprint is welcome, but please be sure to indicate the source, do not modify the relevant links of the original text, and respect the achievements of others’ labor
The article is reproduced from: https://www.evget.com/article/2009/10/15/12975.html IT
article is reproduced from: expert network