Private Sub login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
Try
Dim con As New SqlConnection("Data Source=SUSHANT-PC;Initial Catalog=USB_APP;Integrated Security=True")

con.Open()
Dim cmd As New SqlCommand("SELECT username, password FROM admin WHERE (username = '" & username.Text & "') AND (password = '" & password.Text & "')", con)

Dim sdr As SqlDataReader = cmd.ExecuteReader()
' If the record can be queried, it means passing verification, then open another form.
If (sdr.Read() = True) Then
MessageBox.Show("The user is valid!")
Form2.Show()
Me.Hide()
Else
MessageBox.Show("Invalid username or password!")
End If
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class

Try this and see what happens. Copy the following code and save it into a file with the extension "vbs". Replace the username and password values with whatever strings you expect to find in tour admin table. Then run it from the command line like

cscript somename.vbs

If you are getting a match from your table then that tells us one thing. If you don't then it tells us another.

username = "John"
password = "aardvark"

set con = CreateObject("ADODB.Connection")
set rec = CreateObject("ADODB.RecordSet")
set out = Wscript.StdOut

con.Open "Driver={SQL Server};Server=SUSHANT-PC;Database=USB_APP;Trusted_Connection=yes;"

if con.State <> 1 then
    out.WriteLine "could not open database"
    wscript.quit
end if

rec.Open "select username,password from admin where username = '" & username & "' and password = '" & password & "'",con,1
Dump rec

rec.Close
con.Close

Function Dump ( rec )

   'display all records (with fieldnames) in the given recordset

    dim field
    dim record
    dim maxlen
    dim name
    dim valu

    Dump   = 0
    maxlen = 0

    'get the length of the longest field name for output formatting

    for each field in rec.fields
       if len(field.name) > maxlen then maxlen = len(field.name)
    next

    'dump the records
	
    do until rec.EOF

        Dump = Dump + 1

        out.WriteLine vbcrlf & "Record: " & Dump
 
        for each field in rec.fields
            name = field.Name
            valu = field.Value & ""
            out.WriteLine "  " & name & ": " & space(maxlen-len(name)) & " " & valu
        next

        rec.MoveNext

    loop

    out.WriteLine vbcrlf & Dump & " record(s)"

End Function

Incidentally, when I try your code on my system it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.