2017-10-10 109 views
-4

我無法按字母搜索。像果醬一樣。我必須寫出像詹姆斯這樣的全名。有人可以幫我改變代碼,這樣我就可以用字母搜索。搜索代碼datasheed

這是我的代碼

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 
+3

在您要搜索的文本後面添加%。順便注射。 –

+2

您應該使用'LIKE' ra比'=' – Jaxi

回答

0

像Jaxi說,使用這樣的:

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 

我給你發的代碼將包含「大灌籃」的字符串任何回報,例如改變「詹姆斯」,「一個果醬」,「在一個果醬」,我與樂隊一起果醬「...等......

+0

你是我的英雄,Thx隊友。 –

+0

也許再多一次,當我從Access工作表加載數據時,它會插入所有列。我不想 插入第一個。 是否有插入除「第一列」之外的所有列或列名除外的選項? –

+0

私人小組btnLoad_Click(BYVAL發件人爲System.Object的,BYVALË作爲System.EventArgs)把手btnLoad.C​​lick 昏暗載荷SearchFromTable =新SearchFromTable 隨着Me.DataGridView1 .DataSource = Load.GetMyData _ (「選擇* From tblInfo「) End With End Sub –