搜索代码datasheed

时间:2017-10-10 10:39:19

标签: vb.net

我无法通过信件进行搜索。像Jam这样的东西。我必须像詹姆斯一样写出全名。有人可以帮我改变代码,这样我就可以用字母搜索。

这是我的代码

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim Load As SearchFromTable = New SearchFromTable

    With Me.DataGridView1
        .DataSource = Load.GetMyData _
        ("Select *" _
         + " From tblInfo Where Fname='" & Trim(Me.txtSearch.Text) & "'" _
         + " or Lname='" & Trim(Me.txtSearch.Text) & "'" _
         + " or Department='" & Trim(Me.txtSearch.Text) & "'" _
         + " or Company='" & Trim(Me.txtSearch.Text) & "'")
    End With

End Sub

1 个答案:

答案 0 :(得分:0)

像Jaxi所说,使用LIKE:

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim Load As SearchFromTable = New SearchFromTable

    With Me.DataGridView1
        .DataSource = Load.GetMyData _
        ("Select *" _
         + " From tblInfo Where Fname like '%" & Trim(Me.txtSearch.Text) & "%'" _
         + " or Lname like '%" & Trim(Me.txtSearch.Text) & "%'" _
         + " or Department like '%" & Trim(Me.txtSearch.Text) & "%'" _
         + " or Company like '%" & Trim(Me.txtSearch.Text) & "%'")
    End With

End Sub

我对你的代码所做的更改将返回包含" Jam"的字符串中的任何内容,例如" James"," A Jam",&# 34;在Jam"中,我和乐队一起Jam" ......等......