我在这里做错了什么?我收到一个错误:
语法不正确=
在这行代码上:
Dim SqlDataReader As SqlClient.SqlDataReader = SQLCommad.ExecuteReader()
我的代码:
Dim Username = TUserName.Text
Dim Password = TPassword.Text
Dim SqlConnection = New SqlClient.SqlConnection(My.Settings.DBConnection.ToString)
Dim SQLCommand = New SqlClient.SqlCommand("select * from " + My.Settings.TableName.ToString + "Where EmpID = " + Username, SqlConnection)
SqlConnection.Open()
Dim SqlDataReader As SqlClient.SqlDataReader = SQLCommand.ExecuteReader
While (SqlDataReader.Read)
If Username = SqlDataReader(1).ToString And Password = SqlDataReader(20).ToString Then
If eEncrypt(Username, Password) Then
MsgBox("You are NOT logged in")
Else
MsgBox("You are logged in")
End If
End If
End While
SqlConnection.Close()
答案 0 :(得分:0)
你错过括号
Dim SqlDataReader As SqlClient.SqlDataReader = SQLCommad.ExecuteReader()
答案 1 :(得分:0)
这行代码
Dim SQLCommand = New SqlClient.SqlCommand(" select * from" + My.Settings.TableName.ToString +" Where EmpID =" + Username,SqlConnection)
应该是
Dim SQLCommand = New SqlClient.SqlCommand(" select * from" + My.Settings.TableName.ToString +" Where EmpID ='" + Username +& #34;'",SqlConnection)
从手机发布。
答案 2 :(得分:0)
这应该有效,看看如何添加参数
Dim Username = TUserName.Text
Dim Password = TPassword.Text
Dim SqlConnection = New SqlClient.SqlConnection(My.Settings.DBConnection.ToString)
Dim SQLCommand = New SqlClient.SqlCommand("select * from " + My.Settings.TableName.ToString + "Where EmpID = @Username", SqlConnection)
SQLCommand.Parameters.AddWithValue("@Username", Username)
SqlConnection.Open()
Dim SqlDataReader As SqlClient.SqlDataReader = SQLCommand.ExecuteReader()
While (SqlDataReader.Read)
If Username = SqlDataReader(1).ToString And Password = SqlDataReader(20).ToString Then
If eEncrypt(Username, Password) Then
MsgBox("You are NOT logged in")
Else
MsgBox("You are logged in")
End If
End If
End While
SqlConnection.Close()