答案 0 :(得分:0)
不是我们.AddWithValue。参见http://www.dbdelta.com/addwithvalue-is-evil/ 和 https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/ 还有一个: https://dba.stackexchange.com/questions/195937/addwithvalue-performance-and-plan-cache-implications
您所需要的只是计数,以查看这是否是有效用户。不要不必要地检索数据。
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