This is a fingerprint verification application. When verifying,it loops through the table. if the current fingerprint template is the first one on the table row it verifies it correctly. But if the current fingerprint template is located on the 2nd or later rows, it loops through the table and at the first row it rejects the template as not verified, but subsequently after looping through the rows the fingerprint is verified, if indeed it has been stored in the table. My question is how can l loop through all the rows in the table and before l can get the result l desire if verified or not. Below is the code snippet. Please help

Private Sub VerifyBiometric_Load(ByVal sender As System.Object, ByVal e 
As System.EventArgs) Handles MyBase.Load

Dim sqlCommand As MySqlCommand = New MySqlCommand()
Dim cn As New MySqlConnection(ConnectString())
cn.Open()
sqlCommand.CommandText = "Select * from ecms.fingerprint"
sqlCommand.CommandType = CommandType.Text
sqlCommand.Connection = cn
Dim sqlCommand As MySqlCommand = New MySqlCommand()
Dim cn As New MySqlConnection(ConnectString())
cn.Open()
sqlCommand.CommandText = "Select * from ecms.fingerprint"
sqlCommand.CommandType = CommandType.Text
sqlCommand.Connection = cn

Dim dataSet As DataSet = New DataSet()
Dim adapter As MySqlDataAdapter = New MySqlDataAdapter(sqlCommand)

Dim dt As New DataTable
Dim dr As DataRow

Try
    adapter.Fill(dt)
    For Each dr In dt.Rows
        Dim bytes As Byte() = Nothing
        bytes = dr.Item("FingerP")

        Dim template = New DPFP.Template()
        template.DeSerialize(bytes)
        'Perform match
        matcher.Verify(FeatureSet, template, matchResult)
        If matchResult.Verified Then
            EventHandlerStatus = Gui.EventHandlerStatus.Success
            MessageBox.Show("Verified!")
            Exit For 'success

        End If
        If Not matchResult.Verified Then EventHandlerStatus = Gui.EventHandlerStatus.Failure

        MessageBox.Show("Verification failed, User does not exist")
        'Exit For 'failure
    Next
Finally

    adapter.Dispose()
    cn.Close()
   End Try

End Sub

Recommended Answers

All 2 Replies

Just don't exit out of your "For...Next" loop until you've varified the print against all of your stored rows.

Also I would suggest you not double up on the "If this..." "If NOT this...".
Use the "If this... Then this... Else this... End If"
Adjust your Code Ln: 31 to Ln: 48 as below:

Original Code:

        'Perform match
        matcher.Verify(FeatureSet, template, matchResult)
        If matchResult.Verified Then
            EventHandlerStatus = Gui.EventHandlerStatus.Success
            MessageBox.Show("Verified!")
            Exit For 'success

        End If
        If Not matchResult.Verified Then EventHandlerStatus = Gui.EventHandlerStatus.Failure

        MessageBox.Show("Verification failed, User does not exist")
        'Exit For 'failure
    Next
Finally

    adapter.Dispose()
    cn.Close()
   End Try

Suggested Code: (See comments for reasoning and explaination.)

        ' Perform match
        matcher.Verify(FeatureSet, template, matchResult)
        ' Check your match result...
        If matchResult.Verified Then
            ' Set your EventHandlerStatus...
            EventHandlerStatus = Gui.EventHandlerStatus.Success
            MessageBox.Show("Verified!") ' Notify the user....
            ' Exit For ' Success - Use a "Goto" instead of "Exit For"
            Goto Matched ' Success - Leave the "For" loop here with "Goto"...
        Else ' Same as "If NOT matchResult.Verified"
            ' Set your EventHandlerStatus...
            EventHandlerStatus = Gui.EventHandlerStatus.Failure
            ' NO Exit For ' Failure - Do NOT leave the "For" loop here...
        End If
    Next
NoMatch: ' Display the "Verification failed..." message after all possible rows have been reviewed.
        MessageBox.Show("Verification failed, User does not exist")
Matched: ' Jump over the "NoMatch" above, from the "Goto Matched" instructions, if Match found.

Finally

    adapter.Dispose()
    cn.Close()
   End Try

The suggested should be the same number of lines of code as the original.
The code is only rearranged a bit to work.
It may seem to look longer, but only due to all of my comments and notes.

commented: Keep looking! +12
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.