0

I am tring to do a search on lastname and firstname with the autocomplete ajax control. But I am getting the error An expression of non-boolean type specified in a context where a condition is expected, near ','. Any idea what I am doing wrong? There error is occuring at the Words(0) line. Thanks!

Public Function GetCompletionList(prefixText As String, count As Integer, ByVal contextKey As String) As String()
    Try
        Dim words As String() = prefixText.Split(New Char() {","c})
        Dim Con As SqlConnection
        Dim cmd As SqlCommand
        Con = New SqlConnection
        Dim test As String
        test = contextKey
        Con.ConnectionString = ""
        Con.Open()

        cmd = New SqlCommand
        cmd.Connection = Con
        cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)], [Provider First Name],[Provider First Line Business Mailing Address], [Provider Business Mailing Address City Name], [Provider Business Mailing Address State Name], [Provider Business Mailing Address Postal Code] FROM NPIData WHERE ([Provider Business Mailing Address State Name] = @State) AND ('" & words(0) & "','" & words(1) & "' LIKE N'%' + @Provider + N'%') ORDER BY [Provider First Name]"
        cmd.Parameters.AddWithValue("@Provider", prefixText)
        cmd.Parameters.AddWithValue("@State", contextKey)
        Dim customers As List(Of String) = New List(Of String)
        Dim reader As SqlDataReader = cmd.ExecuteReader()


        While reader.Read
            customers.Add(reader("Provider Last Name (Legal Name)").ToString + ", " + reader("Provider First Name").ToString + "   " + reader("Provider First Line Business Mailing Address").ToString + "  " + reader("Provider Business Mailing Address City Name").ToString + ", " + reader("Provider Business Mailing Address State Name").ToString + "  " + reader("Provider Business Mailing Address Postal Code").ToString + "  " + reader("NPI").ToString)

        End While


        Con.Close()

        Return customers.ToArray
    Catch ex As Exception

    End Try

End Function
4

1 回答 1

0

在你说你失败的那一行,你有

('" & words(0) & "','" & words(1) & "' LIKE N'%' + @Provider + N'%')

如果 word(0) 包含 txt1 并且 worda (1) 包含 txt2,则计算结果为

'txt1','txt2'喜欢 ...

您不能将逗号分隔的字符串列表与 LIKE 进行比较。

我不知道你是否打算连接 words(0) 和 words(1) 以获得

'txt1txt2' LIKE...

这将需要

('" & words(0) & words(1) & "' LIKE N'%' + @Provider + N'%')

或进行单独比较,这将需要

('" & words(0) & "' LIKE N'%' + @Provider + N'%' OR ' & words(1) & "' LIKE N'%' + @Provider + N'%')
于 2013-07-09T14:09:07.730 回答