Hi Team,
Below code is working fine. Main thing is if i entered wrong username and password it was not displaying message MsgBox("invalid username or password"). please help ow to validate it using sql. what is going wrong. thanks in advance.
Below code is working fine. Main thing is if i entered wrong username and password it was not displaying message MsgBox("invalid username or password"). please help ow to validate it using sql. what is going wrong. thanks in advance.
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
con.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from login where username in('" & TextBox1.Text & "')and password='" & TextBox2.Text & "'"
da = New SqlDataAdapter(cmd.CommandText, con)
da.Fill(ds, "login")
maxcount = ds.Tables(0).Rows.Count - 1
Dim a(maxcount), b(maxcount) As String
For i = 0 To maxcount
a(i) = ds.Tables("login").Rows(i).Item(0)
b(i) = ds.Tables("login").Rows(i).Item(1)
If a(i) = TextBox1.Text And b(i) = TextBox2.Text Then
Me.Hide()
Form2.Show()
Else
MsgBox("invalid username or password")
End If
Next
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
con.Close()
End Sub

Comment