how to save byte-array with Dapper and sqlite insert statement

bytearray dapper insert sqlite3 vb.net

Question

I have the following code:

Shared Sub ExecSQL(ByVal connection As SQLiteConnection, ByVal commandText As String, Optional ByVal param As Object = Nothing)
    If connection Is Nothing Then
        Throw New NullReferenceException("Connection required!")
    End If

    If connection.State <> ConnectionState.Open Then
        connection.Open()
    End If

    connection.Execute(commandText, param)
End Sub

Shared Sub SaveFingerPrints(p As Person)
    For Each f In p.Fingerprints
        ExecSQL($"insert into Prints(id,finger,image,template) values({p.Id},{f.Finger},{f.AsImageData},{f.Template});")
    Next
End Sub

I end up with the following insert statement:

insert into Prints(id,finger,image,template) values(1,RightThumb,System.Byte[],System.Byte[]);

Please how can I fix this

Accepted Answer

Got it!

Shared Sub SavePrints(p As Person)
    For Each f In p.Fingerprints
        cn.Execute("insert into Prints(id,finger,image,template) values(@id,@Finger,@image,@template)",
                   New With {
                   .id = p.Id,
                   .finger = CInt(f.Finger),
                   .image = f.AsImageData,
                   .template = f.Template})
    Next
End Sub


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why