0

How do i go about creating an exception handler when i want to login to my form to access the rest of my forms. The username and password are linked to server.What if it doesnt connect to server? here is coding for me to login:

 Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    If (txtUName.Text = "-") Or (txtUName.Text = "0") Or (txtUName.Text = "") Or (txtPass.Text = "0") Or (txtPass.Text = "-") Or (txtPass.Text = "") Then
        MessageBox.Show("Invalid Entry", "ErrorMessageBox", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txtUName.Text = ""
        txtPass.Text = ""
        Return
    End If
    empeid = txtUName.Text
    DatasetLogin1.Clear()
    sqldLoginadapter.SelectCommand.Parameters("@EID").Value = txtUName.Text
    sqldLoginadapter.SelectCommand.Parameters("@EPass").Value = txtPass.Text
    sqldLoginadapter.Fill(DatasetLogin1, "empdetails")
    If (DatasetLogin1.Tables("empdetails").Rows.Count > 0) Then
        MessageBox.Show("Login Successfull! Welcome Employee: " & empeid, "MessageBox", MessageBoxButtons.OK, MessageBoxIcon.Information)
        txtUName.Text = ""
        txtPass.Text = ""
        Me.Hide()
        PDL_MainMenu_Form.Show()
    Else
        MessageBox.Show("Not Registered Employee Details!. Please Try Again", "ErrorMessageBox", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txtUName.Text = ""
        txtPass.Text = ""
        Return
    End If
End Sub

Thanks

4
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by darthswift00
0

Whenever u write a coding for Database connection use the try catch block

Try

' *ur complete code goes here * 

Catch ex as Exception
MsgBox(ex.Message) ' if u get an error in above coding it will be passed to catch block and will display the error
End try
0

And also use the finally bloack to close ur connection to database or to dispose any objects...

This question has already been answered. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.