sql - 我正在使用SQL进行VB登录,并使用 “incorrect syntax near word user”(粗体行)显示错误。有什么建议吗?

标签 sql vb.net visual-studio login syntax-error

Public Class Login
Inherits System.Web.UI.Page
Dim connectionString As String = "Data Source=*****;Initial Catalog=AlphaSYS39414;Persist Security Info=True;User ID=******;Password=********"

Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
    Using connection As New SqlConnection(connectionString)
        Dim account As String = txtusername.Text
        Dim mypassword As String = txtpassword.Text
        Dim sqlCommand As New  _
            SqlCommand("SELECT * FROM User WHERE @User_ID AND @Password", connection)
        sqlCommand.Parameters.AddWithValue("@User_ID", account)
        sqlCommand.Parameters.AddWithValue("@Password", mypassword)
        connection.Open()
        **Dim reader As SqlDataReader = sqlCommand.ExecuteReader()**
        Dim values As New ArrayList()
        If reader.Read Then
            Response.Redirect("https://google.com")
            'Dim returnedUsername As New String(reader("account"))
            'Dim returnedPassword As New String(reader("mypassword"))
        Else
            Response.Redirect("https://yahoo.com")
        End If
    End Using

End Sub
End Class

最佳答案

Userthis链接上列出的保留关键字。

您应该更改此代码

SqlCommand("SELECT * FROM User WHERE @User_ID AND @Password", connection)

对此
SqlCommand("SELECT * FROM [User] WHERE @User_ID AND @Password", connection)

关于sql - 我正在使用SQL进行VB登录,并使用 “incorrect syntax near word user”(粗体行)显示错误。有什么建议吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775309/

相关文章:

c++ - 如何在 C++ 中关闭 ASSERT( x )?

使用 VC++ Express 在 C 中创建文本文件

sql - INSERT 和 DELETE 在同一个事务中?

mysql - SQL 列表项不重复第一个

mysql - SQL选择属于同一对象的用户

c# - 如何从另一个项目中调用一个Form

sql - 如何找出在 SQL Server 中使用对主键的引用?

asp.net - txt 名字和名字 Txt

vb.net - 2个物体之间的线性运动

c++ - 使用 TBB 时找不到 msvcp80d.dll