我为我的程序制作了一个简单的登录代码。
在我的网站上,我为存储用户名、电子邮件和密码的程序创建了一个 mysql 数据库,我已查询数据库 2 次以插入 2 个帐户。
我可以使用第一个帐户登录而不会出现问题,但使用第二个和第三个帐户则不能,依此类推。
无论如何,这是代码:
Dim dbConn As New MySqlConnection
Dim UsernameVerify As New MySqlCommand
Dim PasswordVerify As New MySqlCommand
Dim EmailVerify As New MySqlCommand
Dim typeverify As New MySqlCommand
Dim lgnUsername As String
Dim lgnPassword As String
Dim lgnEmail As String
Dim lgntype As String
'server info
dbConn.ConnectionString = "server=*************;UserID=*******;password=********;database=*****"
Try
dbConn.Open()
UsernameVerify.Connection = dbConn
UsernameVerify.CommandText = "Select USERNAME from users"
PasswordVerify.Connection = dbConn
PasswordVerify.CommandText = "Select PASSWORD from users"
EmailVerify.Connection = dbConn
EmailVerify.CommandText = "Select EMAIL from users"
typeverify.Connection = dbConn
typeverify.CommandText = "Select TYPE from users"
lgnUsername = UsernameVerify.ExecuteScalar
lgnPassword = PasswordVerify.ExecuteScalar
lgnEmail = EmailVerify.ExecuteScalar
lgntype = typeverify.ExecuteScalar
dbConn.Close()
If ComboBox1.Text = lgnUsername And ComboBox2.Text = lgnPassword And ComboBox3.Text = lgnEmail And ComboBox4.Text = lgntype Then
Panel1.BackgroundImage = mpng2
Label5.Text = "Succesfully verified user !"
Me.Close()
Else
Panel1.BackgroundImage = mpng
Label5.Text = "Could not find user check your credentials"
ComboBox1.Focus()
End If
Catch ex As MySqlException
Label5.Text = "Error while verifying "
MessageBox.Show("Error when connecting to database|" + ex.Message)
dbConn.Dispose()
verifying.Close()
End Try
有谁知道如何解决这个问题。
我已经在考虑使用 while 循环或其他东西,或者还有其他东西吗?