я выбрал с dropwdonlist и текстовое поле из SQLServer в другой форме в осины vb.net но дает мне ошибки неправильный синтаксис около как сценария является то, чтоНеверный синтаксис рядом с ключевым словом «Like». В.Б чистый
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
ошибка в том, что
Некорректное синтаксис рядом с ключевым словом «Like».
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 = _
Это SQL Injection приглашение вместо веб-приложение. Используйте параметризованные запросы вместо конкатенации строк. Тем более с веб-приложением, где строка sql построена из url-параметров. –
"&" не является шаблоном SQL. –
этот скрипт из книги greg bucek asp_net и & is from vb_net – monster