0
何が問題になったのか分かりません。私はVBに新しいです。誰か助けてくれますか?たぶん私のコードを修正すると、私はこのログインフォームでずっと時間を過ごしています。ありがとう!ここに私のコードです。 ところで、私は3列のテーブルを持っています。ユーザー名、パスワード、特権。ログイン資格情報を入力するたびに、Msgboxが再度表示されます。VB.netでのMySQLのログイン
Imports MySql.Data.MySqlClient
Public Class LoginForm
Dim cn As New MySqlConnection
Dim cmd As MySqlCommand
Dim reader As MySqlDataAdapter
Private Sub OK_Click(sender As Object, e As EventArgs) Handles OK.Click
Dim tblUser As New DataTable
Try
If PasswordTextBox.Text = "" Or UsernameTextBox.Text = "" Then
MessageBox.Show("Please provide your login credentials!")
Else
Dim sql As String
sql = "SELECT * from user_account where username = '" & UsernameTextBox.Text & "' and password = '" & PasswordTextBox.Text & "'"
Using con As New MySqlConnection(My.Settings.ConnectionString)
With cmd
.Connection = con
.CommandText = sql
End With
reader.SelectCommand = cmd
reader.Fill(tblUser)
If tblUser.Rows.Count > 0 Then
Dim userType As String
userType = tblUser.Rows(0).Item(2)
If userType = "admin" Then
MsgBox("Welcome, Admin!")
frmAdminMain.Show()
ElseIf userType = "encoder" Then
MsgBox("Welcome, User!")
MainForm.Show()
End If
Else
MsgBox("Invalid Credentials!")
End If
reader.Dispose()
End Using
End If
Catch ex As Exception
MsgBox("Try Again!")
End Try
End Sub
私はちょうどコメントのように私の答えを送っていただろうが、私はそれのためにもっと評判が必要です。 –
MsgBox(ex.ToString)をキャッチ部分に貼り付けますか? – noob
System.NullReferenceException:オブジェクト参照がWindowsApplication1のオブジェクトのインスタンスに設定されていません... vb:行19 そして、19行目は.Connection = con – noob