【发布时间】:2011-10-15 03:13:54
【问题描述】:
任何人都知道为什么以下不起作用?
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()
如果我删除与 phrase 相关的任何内容,它会再次开始工作,即:
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()
我没有收到任何错误,它只是返回一个空白字符串。
【问题讨论】:
标签: .net asp.net vb.net .net-3.5 asp.net-3.5