搜索包含字符串访问数据库的字符串

时间:2018-05-31 12:26:15

标签: vb.net access-vba

我需要帮助搜索包含字符串的字符串(将显示包含该文本示例的所有文本:搜索包含注射器的字符串显示所有注射器,如注射器10ML,注射器20ML,ABL注射器)

这是我的代码到目前为止,我的项目已连接到访问数据库。

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

        Dim stock As String
        stock = cmbSearch.Text

        Select Case stock
            Case "Stock Level"
                Me.Sheet1BindingSource.Filter = "Stock = '" & txtSearch.Text & "'"
            Case "Description"
                Me.Sheet1BindingSource.Filter = "Description = '" & txtSearch.Text & "'"
            Case "Article"
                Me.Sheet1BindingSource.Filter = "Article = '" & txtSearch.Text & "'"
            Case "Merche Cat"
                Me.Sheet1BindingSource.Filter = "Merche Category = '" & txtSearch.Text & "'"
            Case "Merche Dis"
                Me.Sheet1BindingSource.Filter = "Merche Description = '" & txtSearch.Text & "'"
        End Select

    End Sub
End Class

我希望它作为描述,因为项目的描述包含像注射器一样。

1 个答案:

答案 0 :(得分:0)

在Access VBA中使用LIKE与SQL Server不同 - 将LIKE与通配符一起使用,  例如:

"Stock LIKE '*" & txtsearch.text & "*'"