Griaule Biometrics

Home » Forums » FINGERPRINT SDK » VB Specific » trouble to save a fingerprint in a SQL Server database
8 replies [Last post]
Anonymous
Rate this post:
0
No votes yet
trouble to save a fingerprint in a SQL Server database

I'm hope that can understand me.. my english isn't good...

I'm modify the sample in VB2005, to use with a SQL Server Express database.
Firstly, I made a table named 'enroll' in SQL Server, and I agree 2 fields exactly like Access DB example, ID and template. The field "ID" is Int datatype with the property "Is Identity" to Yes value (to simulate an autoincrement field), and the "template" field is Image datatype (in this point I'm not be sure..)
Then, I modify all OleDB objects to SQLClient objects. I think that the conection to DB works fine, because I don't receive any error message..

Well, when I press the buttom "Enroll" of the sample in runtime, the app stoped in this part of code:

' Add template to database. Returns added template ID.
Public Function AddTemplate(ByRef template As TTemplate) As Long
Dim da As New SqlDataAdapter("select * from enroll", connection)

' Create SQL command containing ? parameter for BLOB.
da.InsertCommand = New SqlCommand("INSERT INTO enroll (template) Values(?)", connection)
da.InsertCommand.CommandType = CommandType.Text
da.InsertCommand.Parameters.Add("@template", SqlDbType.Image, template.Size, "template")

' Open connection
connection.Open()

' Fill DataSet.
Dim enroll As DataSet = New DataSet
da.Fill(enroll, "enroll")

' Add a new row.
' Create parameter for ? contained in the SQL statement.
Dim newRow As DataRow = enroll.Tables("enroll").NewRow()
newRow("template") = template.tpt
enroll.Tables("enroll").Rows.Add(newRow)

' Include an event to fill in the Autonumber value.
AddHandler da.RowUpdated, New SqlRowUpdatedEventHandler(AddressOf OnRowUpdated)

' Update DataSet.
da.Update(enroll, "enroll")
connection.Close()

' return ID
'Return 1
Return newRow("ID")

End Function

' Event procedure for OnRowUpdated
Private Sub OnRowUpdated(ByVal sender As Object, ByVal args As SqlRowUpdatedEventArgs)
' Include a variable and a command to retrieve identity value
' from Access database.
Dim newID As Integer = 0
Dim idCMD As SqlCommand = New SqlCommand("SELECT @@IDENTITY", connection)

If args.StatementType = StatementType.Insert Then
' Retrieve identity value and store it in column
newID = CInt(idCMD.ExecuteScalar())
args.Row("ID") = newID
End If
End Sub

can anyone tell me what I do wrong?

Thanks in advance

Euclides Chavez

Anonymous
Rate this post:
0
No votes yet

Yo probe con este código y funciona!!

	' Add template to database. Returns added template ID.
	Public Function AddTemplate(ByRef template As TTemplate) As Long

Dim da As New SqlDataAdapter("select * from enroll", connection)

' Create SQL command containing ? parameter for BLOB.
da.InsertCommand = New SqlCommand("INSERT INTO enroll (template) Values(@template)", connection)
da.InsertCommand.CommandType = CommandType.Text
da.InsertCommand.Parameters.Add("@template", SqlDbType.VarBinary, template.Size, "template")

' Open connection
connection.Open()
' Fill DataSet.
Dim enroll As DataSet = New DataSet
da.Fill(enroll, "enroll")

' Add a new row.
' Create parameter for ? contained in the SQL statement.
Dim newRow As DataRow = enroll.Tables("enroll").NewRow()
newRow("template") = template.tpt
enroll.Tables("enroll").Rows.Add(newRow)

' Include an event to fill in the Autonumber value.
'AddHandler da.RowUpdated, New SqlRowUpdatedEventHandler(AddressOf OnRowUpdated)

' Update DataSet.
da.Update(enroll, "enroll")
connection.Close()

' return ID
'Return newRow("ID")
Return 1
End Function


En sintesis, para usar el ejemplo que trae el GrFinger para VB 2005 con SQL Server, hay que cambiar los objetos OleDB por los objetos SQLClient.

En la BD el tipo de datos que hay q usar es el IMAGE (en Access es el Ole).

En la instruccion Insert hay que usar '@template' en vez del signo de interrogacion '?' para el parametro de la huella.

Y por ultimo en la linea

da.InsertCommand.Parameters.Add("@template", SqlDbType.VarBinary, template.Size, "template")

se usa 'SqlDbType.VarBinary' en vez de 'OleDbType.Binary' que es utilizado en el ejemplo con Access..

Demas esta decir que en la BD en SQL Server hay que tener una tabla llamada 'enroll' con los campos ID (Int con la onda autoincrementable) y 'template' (con el tipo de datos IMAGE).

Bueno, espero que esto le sirva a alguno..


Saludos desde Paraguay

Euclides Chavez


adlin.l
Offline
Joined: 2008-09-19
Rate this post:
0
No votes yet

echavez wrote:
I'm hope that can understand me.. my english isn't good...

I'm modify the sample in VB2005, to use with a SQL Server Express database.......
Then, I modify all OleDB objects to SQLClient objects. I think that the conection to DB works fine, because I don't receive any error message.....

Dear Euclides Chavez,

Hi, I'm also facing the same problem where I try use SQL Express as database. At first the program run properly but when click on "Enroll" button it would capture the image. Any help.....

Regards,
Kent

Anonymous
Rate this post:
0
No votes yet

kent82 wrote:
Dear Euclides Chavez,

Hi, I'm also facing the same problem where I try use SQL Express as database. At first the program run properly but when click on "Enroll" button it would capture the image. Any help.....

Regards,
Kent

Dear Kent,

You have to try the solution that I explain in the post before your post, only you have to traslate to english.. (I reply in spanish..)
Well, in otherwise, the solution are next:

Try this code in AddTemplate function:

 ' Add template to database. Returns added template ID. 
   Public Function AddTemplate(ByRef template As TTemplate) As Long 

Dim da As New SqlDataAdapter("select * from enroll", connection)

' Create SQL command containing ? parameter for BLOB.
da.InsertCommand = New SqlCommand("INSERT INTO enroll (template) Values(@template)", connection)
da.InsertCommand.CommandType = CommandType.Text
da.InsertCommand.Parameters.Add("@template", SqlDbType.VarBinary, template.Size, "template")

' Open connection
connection.Open()
' Fill DataSet.
Dim enroll As DataSet = New DataSet
da.Fill(enroll, "enroll")

' Add a new row.
' Create parameter for ? contained in the SQL statement.
Dim newRow As DataRow = enroll.Tables("enroll").NewRow()
newRow("template") = template.tpt
enroll.Tables("enroll").Rows.Add(newRow)

' Include an event to fill in the Autonumber value.
'AddHandler da.RowUpdated, New SqlRowUpdatedEventHandler(AddressOf OnRowUpdated)

' Update DataSet.
da.Update(enroll, "enroll")
connection.Close()

' return ID
'Return newRow("ID")
Return 1
End Function


Then, you have to change all objects OleDB to SQLClient in the sample of GrFinger for VB 2005.

The datatype to store the fingerprint in SQLServer is IMAGE.

Note that in the INSERT line, you most use '@template' and not '?' like sample for Access.

At last, in the line:

da.InsertCommand.Parameters.Add("@template", SqlDbType.VarBinary, template.Size, "template")

you have to use 'SqlDbType.VarBinary' in place of 'OleDbType.Binary' of Access sample.

You most have a table in your SQL Sever database named "enroll" with the fields 'ID' (Int datatype, with autoincrement property) and 'template' (Image datatype).

I hope this help you.


Regards from Paraguay


Euclides Chavez


adlin.l
Offline
Joined: 2008-09-19
Rate this post:
0
No votes yet

Dear Euclides Chavez,

Thanks for your translation solution. I really appreciate for your help.

Another question is what do you get in your SQL Server database after capture the fingerrpints? Image or Binary Data?

I get in "Binary Data" form when I run in C# sample. Any help if I want it be an image in the database?

Regards from Malaysia,
Kent

Anonymous
Rate this post:
0
No votes yet

Kent,
I think that the data are store in binary type and not as image type but use the Image datatype to store them (I prove with Access report to see the fingerprint picture, but apper a blank image)..

Euclides

adlin.l
Offline
Joined: 2008-09-19
Rate this post:
0
No votes yet

Dear Euclides Chavez,

Do you know how to refer a primary key to foreign key?

For example I got 2 table as below:

Customer = {CustomerID,FirstName,LastName}

LoadImage = {fingerprintID,CustomerID,template}

I put the "CustomerID" from table Customer as auto int data type and I

also put the relation with table LoadImage as update and delete cascade.

But I dont know how to get the CustomerID from table Customer to table

LoadImage. Any help....

Regards;
Kent

Anonymous
Rate this post:
0
No votes yet

Kent,
You can use a "Database Diagrams" from Database Explorer on your VB 2005 IDE to do a relations beetwen tables.. but I don't know yet how to refer a foreing key in a form.. I'm a newie in VB 2005 programming.. =)

In VB 6 I use an ActiveX named DBCombo to refer a foreing key of a secondary table with a primary table.. I think that in VB 2005 exist an equivalent control..

Good lucky!

Euclides

fenixke
Offline
Joined: 2009-06-09
Rate this post:
0
No votes yet

Hi,

i i modify the code for it to connect to ms sql. the problem now , i wan the program to add a name field from a textbox and save the current time and date, to the time collum into the database. can anyone help me with this ?

thanks.