用OleDbConnectionStringBuilder对象来构建连接字符串的实例
分类:VB.Net
乐博网lob.cn提示:调试环境为 vs2005 + windows2003 / windows2008 / xp / vista + .NET Framework 2.0
代码如下:
Option Strict On
Imports System.Data.OleDb
Public Class LOB
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click Try
' 利用 OleDbConnectionStringBuilder 对象来构建连接字符串。 Dim connectStringBuilder As New OleDbConnectionStringBuilder() connectStringBuilder.DataSource = "C:\乐博网\Database\乐博网access数据库.mdb" connectStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0"
Using cn As New OleDbConnection(connectStringBuilder.ConnectionString) cn.Open()
Dim ds As New DataSet()
Dim cmdLiming As New OleDbCommand("SELECT * FROM 学生", cn)
Using drLiming As OleDbDataReader = cmdLiming.ExecuteReader()
ds.Load(drLiming, LoadOption.OverwriteChanges, New String() {"学生"})
' 将 BindingSource 组件系结至 DataSet 当中的“学生”数据表。 Me.BindingSource1.DataSource = ds.Tables("学生")
' 将 DataGridView 控件系结至 BindingSource 组件。 Me.DataGridView1.DataSource = Me.BindingSource1
End Using End Using Catch ex As Exception MessageBox.Show(ex.Message, "乐博网提示", MessageBoxButtons.OK, MessageBoxIcon.Stop) End Try End Sub
Private Sub LOB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub End Class
|