Asp.net 什么';这个SELECT语句中有什么错误

Asp.net 什么';这个SELECT语句中有什么错误,asp.net,sql,sql-server,vb.net,Asp.net,Sql,Sql Server,Vb.net,这一行将用蓝线突出显示: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Se

这一行将用蓝线突出显示:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
    Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT * FROM Table1 WHERE Seats ='" & TextBox1.Text & "'", SQLData)

    SQLData.Open()

    Using adapter As New SqlDataAdapter(cmdSelect)
    Using table As New Data.DataTable()
        adapter.Fill(table)
        TextBox1.Text = [String].Join(", ", table.AsEnumerable().[Select](Function(r) r.Field(Of Integer)("seat_select")))
    End Using
    End Using

    SQLData.Close()
End Sub

尝试将代码更改为

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
    Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT * FROM Table1 WHERE Seats ='" & TextBox1.Text & "'", SQLData)

    SQLData.Open()

    Using adapter As New SqlDataAdapter(cmdSelect)
    Using table As New Data.DataTable()
        adapter.Fill(table)
        TextBox1.Text = [String].Join(", ", table.AsEnumerable().[Select](Function(r) r.Field(Of Integer)("seat_select")))
    End Using
    End Using

    SQLData.Close()
End Sub
TextBox1.Text = [String].Join(", ", table.AsEnumerable().[Select](Function(r) r.Field(Of Integer)("seat_select")))

希望这对您有所帮助

您应该使用参数化查询,将文本从textbox直接传递到query是一种可怕的方式。我想使用selct语句//@Andrzej Nosal在textbox 1中显示多字段记录
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
    Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT * FROM Table1 WHERE Seats ='" & TextBox1.Text & "'", SQLData)

    SQLData.Open()

    Using adapter As New SqlDataAdapter(cmdSelect)
    Using table As New Data.DataTable()
        adapter.Fill(table)
        TextBox1.Text = [String].Join(", ", table.AsEnumerable().[Select](Function(r) r.Field(Of Integer)("seat_select")))
    End Using
    End Using

    SQLData.Close()
End Sub