我选择了dropwdonlist和textbox 从sqlserver到asp vb.net中的另一个表单 但是给我错误 附近的语法不正确 脚本就是那个
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Len(Session("LibuserID")) = 0 Then
Response.Redirect("./index.aspx")
End If
Dim DBConn As SqlConnection
Dim DBCommand As SqlDataAdapter
Dim DSPageData As New DataSet
DBConn = New SqlConnection("Data Source=localhost;" & _
"initial catalog=test;Integrated Security=True;")
If Request.QueryString("Type") = "Search" Then
lblMessage.Text = "Resultati Poiska:"
DBCommand = New SqlDataAdapter _
("Select LibBookID,BookTitle,Author,Status " _
& "from LibBooks where " _
& Request.QueryString("ddlSearchField") & "Like '%" _
& Replace(Request.QueryString("txtSearchText"), "'", "''") _
& "&' order by BookTitle", DBConn)
ElseIf Request.QueryString("Type") = "Browse" Then
lblMessage.Text = "kniqi otnosyasiesya k etoy kategorii:"
DBCommand = New SqlDataAdapter _
("select LibBookID,BookTitle,Author,Status " _
& "from LibBooks where " _
& "LibBookCategoryID = " _
& Request.QueryString("LibBookCategoryID") _
& "Order By BookTitle", DBConn)
Else
Response.Redirect("./menu.aspx")
End If
DBCommand.Fill(DSPageData, _
"Books")
dbBooks.DataSource = _
DSPageData.Tables("Books").DefaultView
dbBooks.DataBind()
End Sub
错误是
关键字“赞”附近的语法不正确。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Like'.
Source Error:
Line 33: Response.Redirect("./menu.aspx")
Line 34: End If
Line 35: DBCommand.Fill(DSPageData, _
Line 36: "Books")
Line 37: dbBooks.DataSource = _
答案 0 :(得分:1)
在 LIKE 子句之前添加一个空格。
&安培; Request.QueryString(" ddlSearchField")& "喜欢'%" _
答案 1 :(得分:0)
有人说你应该使用参数化查询而不是这个。
可能你的问题是Request.QueryString("ddlSearchField")
为空或空,所以如果你想将查询更改为参数化,你必须重写所有,如果你只是想让它工作,你必须检查值是null还是空。