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

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!")
MessageBox.Show("Invalid username or password!")
End If
Catch ex As Exception
End Try
End Sub
End Class

Edited 4 Years Ago by sushanttade: new ...doing project work so its urgent

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"
end if

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


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( > maxlen then maxlen = len(

    '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



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

End Function

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

Edited 4 Years Ago by Reverend Jim: n/a

This question has already been answered. Start a new discussion instead.