0

我需要帮助。需要进行密码验证并且不知道为什么它不起作用。有人可以告诉我我的代码缺少什么或者我的思维方式实际上有什么问题吗?我将它连接到 dataset2,其中名为 Users2 的表。表由两列组成:“用户名”和“密码”。Users2BiningSource.Find 应该返回当前查询所在索引的值。返回的值总是-1,我猜的意思是没有找到(假)。我在 Windows 7 上使用 Microsoft Visual Studio 2012 和 SQL Server 2008 SP3。感谢您的时间和帮助!

Imports Hotel_Booking_System.DataSet2TableAdapters



Public Class Logging


Public Sub check_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.Check_Details()
End Sub


Private Sub Quit_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.Close()
End Sub

Public Sub Logging_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Users2TableAdapter.Fill(Me.DataSet2.Users2)
    'TODO: This line of code loads data into the 'DataSet2.Users2' table. You can move,     or remove it, as needed.

End Sub

Public Sub Check_Details()

Me.Users2BindingSource.AddNew()

    Dim Usrnm As String = ""
    Usrnm = txtUsername.Text
    Dim Pswrd As String = ""
    Pswrd = txtPassword.Text
    Dim Found As Integer
    Found = Users2BindingSource.Find("Username", Usrnm)
    Dim Found2 As Integer
    Found2 = Users2BindingSource.Find("Password", Pswrd)


    If Found >= 0 And Found2 >= 0 And Usrnm = "Admin" Then
        Me.Hide()
        Booking.Show()
    ElseIf Found >= 0 And Found2 >= 0 Then
        Me.Hide()
        Rooms.Show()
    Else
        MsgBox("Wrong username or password. Please try again", MsgBoxStyle.DefaultButton1,     "SOMETHING WENT WRONG")
    End If
    Label1.Text = Found 'checking the value of found
    Label2.Text = Found2 ' checking the value of found2
End Sub

End Class
4

0 回答 0