0

嗨,我正在使用下面的代码选择一些数据,并且在“名称”附近出现错误语法不正确。必须声明标量变量“@Provider”。有什么想法吗?谢谢!

 cmd = New SqlCommand
        cmd.Connection = Con
        cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)] FROM NPIData WHERE ([Provider Last Name (Legal Name)] LIKE @Provider Last Name (Legal Name) + '%'"
        cmd.Parameters.AddWithValue("@Provider", prefixText)
        Dim customers As List(Of String) = New List(Of String)
        Dim reader As SqlDataReader = cmd.ExecuteReader()

        While reader.Read
            customers.Add(reader("@Provider").ToString)

        End While
        Con.Close()

        Return customers.ToArray
4

2 回答 2

2

我认为你的代码应该是这样的:

cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)] FROM NPIData WHERE ([Provider Last Name (Legal Name)] LIKE @Provider + '%'"
cmd.Parameters.AddWithValue("@Provider", prefixText)
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)

End While
于 2013-06-26T19:27:05.107 回答
1

参数名称/键不能包含空格。

cmd.Parameters.AddWithValue("@Provide", prefixText)

这是所需的语法。

于 2013-06-26T19:16:14.833 回答