שתף באמצעות


How To Directly Save A Fingerprint Template To Database ?

Question

Monday, January 20, 2014 8:49 AM

how to directly save a fingerprint template to database and retrieve it using SQL database..

i only got this code from the SDK..and i dont know how to save it to database..can help me out ? 

Dim save As New SaveFileDialog()

    save.Filter = "Fingerprint Template File (*.fpt)|*.fpt"

    If save.ShowDialog() = Windows.Forms.DialogResult.OK Then

      ' Write template into the file stream

      Using fs As IO.FileStream = IO.File.Open(save.FileName, IO.FileMode.Create, IO.FileAccess.Write)

        Template.Serialize(fs)

      End Using

    End If

btw..my device is digital persona

All replies (4)

Thursday, January 23, 2014 3:48 AM ✅Answered

Hi,

Welcome to MSDN.

We could save byte array to database, so if you can get the byte array of that template, it should make sense.

Here is a simple sample which could store a fpt file to sql, and get it from sql database by creating a fpt file:

Imports System.Data.SqlClient
Imports System.IO

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        OpenFileDialog1.Filter = "Fingerprint Template File (*.fpt)|*.fpt"
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = OpenFileDialog1.FileName
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            Using con As New SqlConnection("Data Source=WXSERVER12SQL-LAB04;Initial Catalog=VBTestTables;Integrated Security=True")
                Dim contents() As Byte = File.ReadAllBytes(TextBox1.Text)
                con.Open()
                Dim com As New SqlCommand("insert into tbStoreFile(MyBinaryData) values(@file)", con)
                com.Parameters.Add("@file", SqlDbType.VarBinary).Value = contents
                Dim id As Integer = CInt(com.ExecuteNonQuery())
                If id > 0 Then
                    MsgBox("done")
                Else
                    MsgBox("store failed")
                End If
            End Using
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try        
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        SaveFileDialog1.Filter = "Fingerprint Template File (*.fpt)|*.fpt"
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox2.Text = SaveFileDialog1.FileName
        End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Using con As New SqlConnection("Data Source=WXSERVER12SQL-LAB04;Initial Catalog=VBTestTables;Integrated Security=True")
                con.Open()
                Dim com As New SqlCommand("select top 1 MyBinaryData from tbStoreFile", con)'you could change the sql query to the one fit your requirements
                Dim contents() As Byte = CType(com.ExecuteScalar(), Byte())
                Using oFileStream As New System.IO.FileStream(TextBox2.Text, System.IO.FileMode.Create)
                    oFileStream.Write(contents, 0, contents.Length)
                    oFileStream.Close()
                End Using
                MsgBox("done")
            End Using
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
    End Sub
End Class

I just created a table named tbStoreFile, it contains a column named MyBinaryData which is varbinary(max).

The sample just shows the ways saving fpt files to sql and get fpt files form sql.

You could find that these ways all need a byte array, so you could convert that template to byte array, then store that byte array variable to sql database, and when you need the template you could also get the byte array form sql database.

Hope it helps.

Regards.

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Wednesday, January 22, 2014 7:39 AM

Hi

I involved VB expert to further look at this issue. I am moving your thread into the Visual Basic Forum for dedicated support. Thanks for your understanding.

Best Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Saturday, January 25, 2014 1:03 AM

sir ? im a bit confused..in this line here 

Dim contents() As Byte = File.ReadAllBytes(TextBox1.Text)

why textbox ? the sample SDK that i trying to figure out..only got a picturebox to display the scanned fingerprint, listbox for the status and a button for close..

sorry for the noob question..im just really a noob..and so confused bout this stuff..but i really need to finish this before the deadline of my thesis..sigh

plz..sir..enlighten me..tnx in advance


Monday, January 27, 2014 3:11 AM

sir ? im a bit confused..in this line here 

Dim contents() As Byte = File.ReadAllBytes(TextBox1.Text)

why textbox ? the sample SDK that i trying to figure out..only got a picturebox to display the scanned fingerprint, listbox for the status and a button for close..

sorry for the noob question..im just really a noob..and so confused bout this stuff..but i really need to finish this before the deadline of my thesis..sigh

plz..sir..enlighten me..tnx in advance

Hi,

You could treat the TextBox1.Text as a string which is the path of a file, since I set it by the following code:

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        OpenFileDialog1.Filter = "Fingerprint Template File (*.fpt)|*.fpt"
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = OpenFileDialog1.FileName
        End If
    End Sub

That is just a sample, you could change "TextBox1.Text " to the path of your file.

In addition, if your issue is urgent, please contact support at http://support.microsoft.com.

Regards.

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.