私はVB.NETでユーザー検証用のコードを実装しました。私のフォームのテキストボックスにユーザー名とパスワードを入力し、送信ボタンをクリックすると、コードを記述してもメッセージボックスは表示されません。 try-catchブロックに問題がありますか、いくつかのコード行がありませんか?VB.NETでのユーザー検証
誰かがこのコードの何が間違っていると指摘できますか?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = " " Then
MsgBox("Enter a user id and password")
End If
TextBox1.Text = userid
TextBox2.Text = password
Try
myconnection = New SqlConnection("server=PARTH-PC\SQLEXPRESS;uid=sa;pwd=demo;database=fc")
'you need to provide password for sql server
myconnection.Open()
mycommand = New SqlCommand("select * from student where user id='" & TextBox1.Text & "' and password='" & TextBox2.Text & "')", myconnection)
dr = mycommand.ExecuteReader()
Catch ex As Exception
Finally
If (dr IsNot Nothing) Then
If (dr.Read()) Then
MsgBox("User is authenticated")
Form2.Show()
Else
MsgBox("Please enter correct username and password")
End If
End If
End Try
myconnection.Close()
End Sub
End Class
エラーが表示されますか? Form2.Show()は期待通りに機能しますか? – Tariqulazam
@Tariqulazam:いいえ、コントロールは、ブロック.. i dnt knwなぜ –