如何使用digitalpersona sdk直接在数据库中保存指纹

我下载了一个用于我的digitalPersona设备的注册示例代码。 它可能已经注册并validation了指纹,但问题是它将指纹.fpt文件保存在文件夹中。 我想将它保存在数据库中。

这是我到目前为止已经尝试过的。

private void SaveButton_Click(object sender, EventArgs e) { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Fingerprint Template File (*.fpt)|*.fpt"; if (save.ShowDialog() == DialogResult.OK) using (FileStream fs = File.Open(save.FileName, FileMode.Create, FileAccess.Write)) { Template.Serialize(fs); fs.Close(); //Read the file and convert it to byte array string filePath = save.FileName; string filename = Path.GetFileName(filePath); FileStream fst = new FileStream(filePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fst); Byte[] bytes = br.ReadBytes((Int32)fst.Length); br.Close(); fst.Close(); //Insert the file into database SqlConnection cn = new SqlConnection("Data Source=10.115.5.3; Initial Catalog=EnrollmentSampledb;Integrated Security=SSPI;"); SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRSTNAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn); cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Text; cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Text; cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Text; cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes; cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.Now; cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime.Now; cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); } tboxIdNum.Text = ""; tboxFname.Text = ""; tboxLname.Text = ""; } 

这个将指纹文件保存在数据库中,但首先需要将其保存在文件夹中。 我想将它直接保存在数据库中,但我有点混淆如何做到这一点。 我找不到要保存的文件。 T_T我很抱歉有点菜鸟。 有人曾经这样做过吗?

没有经过测试,但我相信代码应该是这样的。 基本上,我们替换一个MemoryStream并在将指纹数据写入其后将其位置设置回0 ,以便可以回读数据并格式化以便存储,从而使其余的代码保持完整(除了名称更改)

 private void SaveButton_Click(object sender, EventArgs e) { MemoryStream fingerprintData = new MemoryStream(); Template.Serialize(fingerprintData); fingerprintData.Position = 0; BinaryReader br = new BinaryReader(fingerprintData); Byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length); //Insert the file into database SqlConnection cn = new SqlConnection("Data Source=10.115.5.3; Initial Catalog=EnrollmentSampledb;Integrated Security=SSPI;"); SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRSTNAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn); cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Text; cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Text; cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Text; cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes; cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.Now; cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime.Now; cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); tboxIdNum.Text = ""; tboxFname.Text = ""; tboxLname.Text = ""; }