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
最佳答案
User
是this链接上列出的保留关键字。
您应该更改此代码
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/