I'm a newbie in VB.Net. I'm creating an application using VB.Net. I have a loggin form which has a username and a password textboxes. I have the following code which is working, which I believe is actually validating the username and password. My hicccup now that I need help is with the If...Else statement. How do I write the codes for the If......Else part, like if the username is correct and the password is wrong then the msg should be "The Password is incorrect" or vise versa, or if both are incorrect then it should also generate a message. My workin code is below, please help with the if...else bit.
Try conn.Open() Dim SelectStm As String = "SELECT * FROM tblStaff WHERE UserName = @UserName AND Password = @Password" Dim objCmd As SqlCommand = New SqlCommand(SelectStm, conn) objCmd.Parameters.AddWithValue("@UserName", txtUserName.Text) objCmd.Parameters.AddWithValue("@Password", Trim(txtPassword.Text)) Dim objAdpt As SqlDataAdapter = New SqlDataAdapter(objCmd) Dim objDt As DataTable = New DataTable() 'Dim objDt As DataTable objAdpt.Fill(objDt) ' objDt = New DataTable() or Overall is: "Dim objDt As New DataTable" If objDt.Rows.Count > 0 Then 'If user is found, then show the following Me.grpAttendenceCheck.Visible = True Me.grpAttendenceCheck.Size = New System.Drawing.Size(510, 157) Me.grpPrintTime.Visible = False Else If (MessageBox.Show("The username and password is incorrect, please confirm and enter them again", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK) Then txtPassword.Text = "" txtUserName.Text = "" txtUserName.SelectedIndex = -1 Else End End If End If conn.Close() Catch ex As Exception MessageBox.Show("Failure") End Try