How to save Biometric Template directly into Database (VB.Net)

I already managed to get the biometric template data but unfortunately I cannot save or insert it directly into the Database. I cannot convert the template into bytes and dump it to table. This is my code:

Private Sub btnSaveFinger1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveFinger1.Click
    Try
        Dim sql As String
            sql = "INSERT INTO [Kamog_HR].[dbo].[T_FingerPrintMaster] " & _
                    "([fpm_EmployeeID] " & _
                    ",[fpm_FingerIndex] " & _
                    ",[fpm_FingerPrintTemplate] " & _
                    ",[Update_By] " & _
                    ",[Created_Date]) " & _
                    "VALUES " & _
                    "('" & txtEmpID.Text & "' " & _
                    ",0 " & _
                    ",@template " & _
                    ",'SA' " & _
                    ",'" & Now & "') "
        OpenConnection()
        Dim str As New MemoryStream
        Enroller.Template.Serialize(str)
        ExecuteSaveFingerPrint(sql, str)
    Catch ex As Exception
        SetPrompt("Cannot save the fingerprint template")
    Finally
        CloseConnection()
    End Try
End Sub

Public Sub ExecuteSaveFingerPrint(ByVal sql As String, ByVal str As MemoryStream)
    Dim cmd As New SqlCommand(sql, con)
    cmd.CommandTimeout = 0
    Dim serializedTemplate As Byte() = str.ToArray()
    Dim paramater As New SqlParameter("@template", serializedTemplate)
    cmd.Parameters.Add(paramater)
    cmd.ExecuteNonQuery()
End Sub

During cmd.ExecuteNonQuery it return an error message saying

"Conversion failed when converting date and/or time from character string."

Even if I remove the Created_Date into the SQL script same error appears. I don't know why and how can I save or insert the fingerprint template directly into the Database.

Answers


I already solved my own problem. This is the sample code of how did I insert the biometric template into the database:

Private Sub btnSaveFinger1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveFinger1.Click
    Try
        Dim sql As String
        If verifyFingerPrint() = True Then
            sql = ""
        Else
            sql = "INSERT INTO [Kamog_HR].[dbo].[T_FingerPrintMaster] " & _
                    "([fpm_EmployeeID] " & _
                    ",[fpm_FingerIndex] " & _
                    ",[fpm_FingerPrintTemplate] " & _
                    ",[Update_By] " & _
                    ",[Created_Date]) " & _
                    "VALUES " & _
                    "('" & txtEmpID.Text & "' " & _
                    "," & GetFingerID() & " " & _
                    ",@fptemp " & _
                    ",'SA' " & _
                    ",'" & Now & "') "
        End If
        OpenConnection()
        Dim str As New MemoryStream
        Enroller.Template.Serialize(str)
        ExecuteSaveFingerPrint(sql, str)
        MsgBox("Fingerprint Successfully Saved!", vbInformation, "Fingerprint")
    Catch ex As Exception
        MsgBox("Cannot save the fingerprint template. Please try again")
        pbFinger1.Image = Nothing
        pbFinger2.Image = Nothing
        pbFinger3.Image = Nothing
        pbFinger4.Image = Nothing
        FingerIndex = 4
        Enroller.Clear()
        StopCapture()
        OnTemplate(Nothing)
        StartCapture()
    Finally
        CloseConnection()
    End Try
End Sub

Public Sub ExecuteSaveFingerPrint(ByVal sql As String, ByVal str As MemoryStream)
    Dim cmd As New SqlCommand(sql, con)
    cmd.CommandType = CommandType.Text
    Dim serializedTemplate As Byte() = str.ToArray()
    Dim paramater As New SqlParameter("@fptemp", serializedTemplate)
    cmd.Parameters.Add(paramater)
    cmd.ExecuteNonQuery()
End Sub

Thank you guys!


Need Your Help

Initializing end of the string in C

c arrays string

I am learning C now and I'm at the point where I don't really get what is the difference of initializing the end of the string with NULL '\0' character. Below is the example from the book:

SVN Freezes on Commit or Update

svn centos

Running into a weird issue with SVN. I've got a CentOS 6.3 server running SVN version 1.6.11 using LDAP authentication for user login. It's been stable and online since July and has never had any i...