此asp.net代码不起作用

此asp.net代码不起作用,.net,asp.net,vb.net,.net-3.5,asp.net-3.5,.net,Asp.net,Vb.net,.net 3.5,Asp.net 3.5,有人知道为什么下面的方法不起作用吗 Dim strPhrase As String = "'%office%'" objStringBuilder = New StringBuilder() objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString")) objSQLCommand = New SqlCommand("select col1,

有人知道为什么下面的方法不起作用吗

Dim strPhrase As String = "'%office%'"

objStringBuilder = New StringBuilder()

objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))

objSQLCommand = New SqlCommand("select col1, col2 from table1 where phrase like @phrase", objSQLConnection)

objSQLCommand.Parameters.Add("@phrase", SqlDbType.VarChar, 255).Value = strPhrase

objSQLCommand.Connection.Open()
objSQLDataReader = objSQLCommand.ExecuteReader()

While objSQLDataReader.Read()
objStringBuilder.Append(objSQLDataReader("col1") & " - " & objSQLDataReader("col2"))
End While

objSQLDataReader.Close()
objSQLCommand.Connection.Close()

return objStringBuilder.tostring()
如果我删除了与
短语相关的任何内容,它将重新开始工作,即:

objStringBuilder = New StringBuilder()

objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))

objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection)

objSQLCommand.Connection.Open()
objSQLDataReader = objSQLCommand.ExecuteReader()

While objSQLDataReader.Read()
objStringBuilder.Append(objSQLDataReader("col1") & " - " & objSQLDataReader("col2"))
End While

objSQLDataReader.Close()
objSQLCommand.Connection.Close()

return objStringBuilder.tostring()
我没有收到任何错误,它只返回一个空白字符串。

从搜索短语中删除“”后,命令对象将为您处理所有这些。i、 e

Dim strPhrase As String = "%office%"
从搜索短语中删除“”后,command对象将为您处理所有这些内容。i、 e

Dim strPhrase As String = "%office%"
就这样吧

Dim strPhrase As String = "%office%"
Dim strPhrase As String = "%office%"
就这样吧

Dim strPhrase As String = "%office%"
Dim strPhrase As String = "%office%"

你可以这样做

Dim strPhrase As String = "%office%"
Dim strPhrase As String = "%office%"
并将下面的行添加到连接字符串的末尾

allow user variables=true;

你可以这样做

Dim strPhrase As String = "%office%"
Dim strPhrase As String = "%office%"
并将下面的行添加到连接字符串的末尾

allow user variables=true;

面向对象的是vb.net,因此您不需要;它是?不知道VB.NET:)。很高兴知道thoughoops是vb.net,因此您不需要;它是?不知道VB.NET:)。不过很高兴知道