任何人都知道爲什麼以下不起作用?此asp.net代碼不起作用
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()
我沒有得到任何錯誤,它只是返回一個空字符串。
+ 1,歡迎來到四圖俱樂部:D – Town