簡體   English   中英

此asp.net代碼不起作用

[英]This asp.net code is not working

有人知道以下原因為何不起作用嗎?

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()

我沒有收到任何錯誤,它只返回一個空白字符串。

從搜索短語中刪除“”,命令對象將為您處理所有這一切。

Dim strPhrase As String = "%office%"

你可以這樣

Dim strPhrase As String = "%office%"

並將波紋管添加到連接字符串的末尾

allow user variables=true;

像這樣

Dim strPhrase As String = "%office%"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM