Vb.net 我的登录页面有问题。使用sqlite数据库

Vb.net 我的登录页面有问题。使用sqlite数据库,vb.net,Vb.net,以下是我的登录代码: Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click cn = New SQLiteConnection Try With cm .Connection = cn .CommandType = CommandType.Text

以下是我的登录代码:

Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
        cn = New SQLiteConnection
        Try
            With cm
                .Connection = cn
                .CommandType = CommandType.Text
                .CommandText = "SELECT * FROM UserLogin WHERE USERNAME = @USERNAME And PASSWORD= @PASSWORD"
                .Parameters.AddWithValue("@USERNAME", txtUser.Text)
                .Parameters.AddWithValue("@PASSWORD", txtPass.Text)
                Dim reader = cm.ExecuteReader()
                While reader.Read
                    Home.btnstudent.Enabled = True
                    Home.btnlis.Enabled = True
                    Home.btnsubject.Enabled = True
                    Home.btntrans.Enabled = True
                    Home.btnmStudent.Enabled = True
                    Home.btnuser.Enabled = True
                    MessageBox.Show("You are welcome")
                    UserValid = True
                End While
                If UserValid = False Then
                    MessageBox.Show("sorry, Access denied", "Incorrect Password!")
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

不要告诉我们。增加价值。看见 和 还有一个:

您所需要的只是计数,以查看这是否是有效用户。不要不必要地检索数据

Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
    Dim count As Integer
    Using cn = New SQLiteConnection("Your connection string")
        Using cm As New SQLiteCommand("SELECT Count(*) FROM UserLogin WHERE USERNAME = @USERNAME And PASSWORD= @PASSWORD", cn)
            cm.Parameters.Add("@USERNAME", DbType.String).Value = txtUser.Text
            cm.Parameters.Add("@PASSWORD", DbType.String).Value = txtPass.Text
            Try
                cn.Open()
                count = CInt(cm.ExecuteScalar)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Using 'Closes and disposes command
    End Using 'Closes and disposes connection
    'Do all this AFTER the connection and command are closed and disposed
    'Showing a message box while your connection is open can keep the connection open
    'until your user gets back from lunch and clicks OK
    If count = 1 Then
        Home.btnstudent.Enabled = True
        Home.btnlis.Enabled = True
        Home.btnsubject.Enabled = True
        Home.btntrans.Enabled = True
        Home.btnmStudent.Enabled = True
        Home.btnuser.Enabled = True
        MessageBox.Show("You are welcome")
        UserValid = True
    Else
        'Don't tell the user exactly what was wrong with their login.
        MessageBox.Show("sorry, Access denied", "Invalid Login")
    End If

End Sub

我有一个问题是没有细节的问题描述不是有用的。你有什么具体问题?你扔掉了一堆代码,添加了一个无用的图像,没有显示任何类型的问题,没有解释任何问题,也没有问任何问题。请看,然后回来问你的问题。我们非常乐意为您提供帮助,但您必须先做好自己的本分。@Godlover14对堆栈溢出表示感谢的最佳方式是接受答案。请点击答案左侧的复选标记接受我的答案。这将帮助您的问题的未来观众,并为您赢得几分。