我有一个表单,它接受用户在 TextBox 中的输入以在网格上显示(“包含”)记录/数据。但是,我无法实现输入数据的事情。我一直在尝试解决这个问题。Dtatbase 是 MS Access。其他一切正常。感谢任何帮助表示赞赏。
这是我的代码:对于这个查询,我在表单网格中没有得到任何值。
PS:我只是一个初学者:) 谢谢!
Imports System.Data.OleDb
Public Class Form1
Dim dbConnection As OleDbConnection
Dim dbCommand As OleDbCommand
Dim dbDataAdapter As OleDbDataAdapter
Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source=atg.mdb"
Dim dtATG As DataTable
Dim Searchq, SQLStr As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dtATG As New DataTable() ''// Create New Datatable
Searchq = TextBox1.Text
dbDataAdapter = New OleDbDataAdapter
SQLStr = "SELECT * FROM ATG WHERE Term Like " & """%" & CStr(TextBox1.Text) & "%"""
dbDataAdapter.Fill(dtATG)
DataGrid1.DataSource = dtATG
End Sub
End Class