Try Dim Apppath As String = Application.StartupPath '获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称 Dim DatabasePath As String = Apppath & "\MyTest.mdb;" '数据库文件总路径名 Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DatabasePath & _ "Persist Security Info=False" '连接字符串 'Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\AccessDB1\bin\Debug\MyTest.mdb;;Persist Security Info=False" Dim sqlStr As String = "select * FROM TestInfo where 1=1 " If Not String.IsNullOrEmpty(Trim(Me.txtName.Text)) Then '带条件查询 sqlStr &= " and XH like '%" & Trim(Me.txtName.Text) & "%' " End If Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString) OleDbConn.Open() Dim MyDataSet As DataSet = New DataSet() Dim MyOleDataAdapter As OleDbDataAdapter = New OleDbDataAdapter() MyOleDataAdapter.SelectCommand = New OleDbCommand(sqlStr,OleDbConn) MyOleDataAdapter.Fill(MyDataSet) Me.Dg.DataSource = MyDataSet.Tables(0) '绑定DataGrid数据源 MyOleDataAdapter.Dispose() MyDataSet.Dispose() OleDbConn.Close() OleDbConn.Dispose() Catch ex As Exception MessageBox.Show(ex.ToString) End Try源代码的下载