Click here to Skip to main content
14,664,481 members
Rate this:
Please Sign up or sign in to vote.
I'm having trouble saving the template of fingerprint in byte. Can you help me to solve this problem? I wan't to save the fingerprint into the database and retrieve it. I've tried codes from different sites but I can't get what I want. Please help.

What I have tried:

Private Sub enrollment_OnEnroll(ByVal enrollmentControl As DPCtlUruNet.EnrollmentControl, ByVal result As DataResult(Of Fmd), ByVal fingerPosition As Integer) Handles enrollmentControl.OnEnroll
        If enrollmentControl.Reader IsNot Nothing Then
            SendMessage4("OnEnroll:  " & Convert.ToString(enrollmentControl.Reader.Description.Name) & ", finger " & fingerPosition)
            SendMessage4("Enrollment Finger Mask: " & _enrollmentControl.EnrolledFingerMask)
        Else
            SendMessage4("OnEnroll:  No Reader Connected, finger " & fingerPosition)
        End If

        Dim fingerprint As String
        Dim fp() As Byte

        Dim conn0 As New MySqlConnection
        Dim command0 As New MySqlCommand
        conn0.ConnectionString = "SERVER=localhost; USER ID=usr; PASSWORD=usrpass; DATABASE=ams2"
        ' Save the enrollment to file.
        If result IsNot Nothing AndAlso result.Data IsNot Nothing Then
            _sender.Fmds.Add(fingerPosition, result.Data)
            fingerprint = Fmd.SerializeXml(result.Data)

            Try
                fp = result.Data.Bytes
                conn0.Open()
                With command0
                    .Connection = conn0

                    .CommandTimeout = 99999
                    .CommandText = "set net_write_timeout=99999; set net_read_timeout=99999"
                    command0.ExecuteNonQuery()

                    .CommandText = "INSERT INTO pr_fingerprint(EMployee_ID, Finger_ID, Img, template)" & _
                        " VALUES(@EMployee_ID, @Finger_ID, @Img, @template)"
                    .Parameters.AddWithValue("@Employee_ID=", EmployeeID.Text)
                    .Parameters.AddWithValue("@Finger_ID=", fingerPosition)
                    .Parameters.AddWithValue("@Img", fp)
                    .Parameters.AddWithValue("@template", fingerprint)
                    .Parameters.Clear()
                    .ExecuteNonQuery()

                    .CommandText = "UPDATE pr_fingerprint f SET Finger_Name=" & _
                        "(SELECT Finger_Name FROM pr_fingers WHERE Finger_ID=f.`Finger_ID`) " & _
                        "WHERE ISNULL(f.`Finger_Name`)"
                    .ExecuteNonQuery()
                End With

                conn0.Close()
            Catch ex As Exception
                MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace, MsgBoxStyle.Critical, "Error")
            End Try
        End If

        btnCancel.Enabled = False

        _sender.btnIdentificationControl.Enabled = True
    End Sub
Posted
Updated 20-May-19 14:46pm
Comments
Richard MacCutchan 29-Jun-18 4:53am
   
"I'm having trouble ..."
What sort of trouble? Please edit your question and explain clearly what does not work or what incorrect results you are seeing.
ErrorMadness 29-Jun-18 20:27pm
   
Reply Modify the comment. Delete the comment.
I have a problem in comparing the templates, and I found out that the XML was not fully saved in the DB which what causes the trouble. I changed the datatype from Text to Varchar(MAX), and it solved the problem.
Rulph Buwen Tejano 2-Feb-19 12:15pm
   
What part in the code is use to save the fingerprint to database?
ErrorMadness 3-Feb-19 22:02pm
   
This Part:

"INSERT INTO pr_fingerprint(EMployee_ID, Finger_ID, Img, template)" & _
" VALUES(@EMployee_ID, @Finger_ID, @Img, @template)"
.Parameters.AddWithValue("@Employee_ID=", EmployeeID.Text)
.Parameters.AddWithValue("@Finger_ID=", fingerPosition)
.Parameters.AddWithValue("@Img", fp)
.Parameters.AddWithValue("@template", fingerprint)
.Parameters.Clear()
.ExecuteNonQuery()
Rulph Buwen Tejano 23-Feb-19 6:21am
   
thank you :D

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I Already found a solution in how to retrieve and save the fingerprint template, I can now also compare the Templates with the scanned fingerprint.
I used
Fmd.SerializeXml(result.Data)
in saving the fingerprint template and used Varchar(MAX) as the datatype in the database. In comparing the templates I load all the templates from the database into an array
Private fingerList As New List(Of Fmd)

conn0.Open()
        command0.Connection = conn0
        command0.CommandText = "SELECT Template FROM pr_fingerprint"
        reader0 = command0.ExecuteReader
        With reader0
            While .Read
                s = .Item("Template")
                fingerList.Add(Fmd.DeserializeXml(s))
            End While
        End With
        conn0.Close()

I compare the finger templates using
Dim identifyResult = Comparison.Identify(anyFinger, 0, fingerList, thresholdScore, 2)

And It's a success.
   
Comments
raffie gollayan 30-Jan-19 3:22am
   
Good Day sir,

Can i ask for the full source code of your program?

Thank you!
ErrorMadness 30-Jan-19 4:26am
   
The code for deserializing the XML?
XelaFig 16-Oct-20 20:30pm
   
Hi, please could you share the complete code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100