I have problem with my small vb program, just started to learn VB this week.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String
        With record
            s = "SELECT * FROM user1"
            record.Open(s, data)

            If TextBox1.Text = record.Fields(0).Value And TextBox2.Text = record.Fields(1).Value Then
                MsgBox("OKKKK")
            Else
                MsgBox("WROOOOOOOOOOOONG!", MsgBoxStyle.Exclamation)
            End If
        End With
        record.Close()

    End Sub

The program seems to work but it queries only on row 1. Like if I have 2 columns (USERNAME and PASSWORD) with (row 1)ADMIN and ADMIN, (row 2)GUEST and GUEST.

It only displays the msgbox("OKKK") when I enter ADMIn and ADMIN while if I enter GUEST and GUEST, the msgbox("WRRoong!") is executed. How do I get it to work on both login information?

Recommended Answers

All 4 Replies

Did you check both rows rather than the first one only!

How? I did not get what you mean..

You have to have a loop to read all the rows. I am not sure about the code, but I am giving you the idea:-

While Record.Read = true
If TextBox1.Text = record.Fields(0).Value And TextBox2.Text = record.Fields(1).Value Then
MsgBox("OKKKK")
GoTo ENDING
END IF
Record.ReadNext
LOOP

MsgBox("WROOOOOOOOOOOONG!", MsgBoxStyle.Exclamation)

ENDING:
Record.close()
END SUB

The best solution for the problem is to use COUNT() .
Take the user input from textbox and using count findout the number of records in database which satisfies the condition. If it is 1 then say OK (login successful and proceed further) else wrong(login failed)
For this the username field should be the primary key of the table.

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.