Selecting record to display in DataGrid in VB

本帖最後由 X-Engineer 於 2016-8-2 18:10 編輯

請問有咩錯?
想用 textbox.text 在 Access Database (.accdb) 內 search record, 然後顯示在 DataGridView.
Test Result : Error
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: No value given for one or more required parameters.

Thanks a lot!!!!!

Here's my code :
  1.    Private Sub btnName_Click(sender As Object, e As EventArgs) Handles btnName.Click
  2.         con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=|DataDirectory|\TEST.accdb")
  3.         con.Open()
  4.         Dim ds As New DataSet
  5.         Dim dt As New DataTable
  6.         ds.Tables.Add(dt)
  7.         Dim da As New OleDbDataAdapter

  8.         da = New OleDbDataAdapter("SELECT * FROM Person WHERE EnglishName LIKE " + txtSearch.Text, con)
  9.         da.Fill(dt)

  10.         SearchDataGridView.DataSource = dt.DefaultView

  11.         con.Close()

  12.     End Sub
複製代碼

No value given for one or more required parameters.
即係唔夠 param...

TOP

如果是 literal search, LIKE 後面項目要用 「'」 quote包住,
pattern search 的話可能更要在裡面再包一層「%」。

TOP

如果是 literal search, LIKE 後面項目要用 「'」 quote包住,
pattern search 的話可能更要在裡面再包一層 ...
Charcoal99 發表於 2016-8-3 10:33



    Thank you very much.
It works now.
  1. da = New OleDbDataAdapter("SELECT * FROM Person WHERE EnglishName LIKE '%" + txtSearch.Text + "%'", con)
複製代碼

TOP