I'm a newbie to VB.Net and I need an urgent help as I'm developing an application using the VB.Net.
I have a form just like the login form in VB.Net. The usernames are prepopulated on a combobox with datas from the SQL DB backend, and the text box for the password entry is empty. My code is working but what I need help is, for the code to validate the username and password entered against that stored on the SQL DB backend. Like when the user selectes a wrong username but the password entered is correct, there shld be a messagebox like "The username selected is wrong", or if the username is correct and the password entered is wrong then the msg is "The password entered is not correct, please type you password using the right case". My code below as I have said is working but I'm confues as to where I can writer the If....Else statements. Please need an urgent help.
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", cmbUserName.Text) objCmd.Parameters.AddWithValue("@Password", Trim(txtPassword.Text)) Dim objAdpt As SqlDataAdapter = New SqlDataAdapter(objCmd) Dim objDt As DataTable = New DataTable() objAdpt.Fill(objDt) 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 MessageBox.Show("Please enter your right username and password") End If conn.Close() Catch ex As Exception MessageBox.Show("Failure") End Try