我爲我的程序做了一個簡單的登錄代碼。在vb2010中使用mysqlconnector登錄系統
在我的網站上,我已經爲存儲用戶名,電子郵件和密碼的程序創建了一個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循環或者其他什麼東西?
謝謝,它改變了一些事情後工作! – kilianvde 2012-07-06 15:55:34
很高興聽到:)謝謝你的觀點嘿嘿 – Ortund 2012-07-10 14:33:34