C# 如何使用digitalpersona sdk将指纹直接保存在数据库中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17335769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save a fingerprint directly in the database using digitalpersona sdk
提问by bot
I downloaded an Enrollment Sample Code for my digitalPersona device to use. It could already register and verify fingerprints but the problem is that it save its fingerprint .fpt file in a folder. I want to save it in the database.
我下载了供我的 digitalPersona 设备使用的注册示例代码。它已经可以注册和验证指纹,但问题是它将指纹 .fpt 文件保存在一个文件夹中。我想把它保存在数据库中。
This is what I already tried so far.
这是我到目前为止已经尝试过的。
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 = "";
}
This one saves a fingerprint file in the database but it need first to save it in a folder. I want to save it directly in the database but I'm a little confuse how to do it. I can't locate the file to save. T_T I'm sorry a little bit noob. Has anyone has done this before?
这在数据库中保存了一个指纹文件,但首先需要将其保存在一个文件夹中。我想直接将它保存在数据库中,但我有点困惑如何去做。我找不到要保存的文件。T_T 我很抱歉有点菜鸟。有没有人做过这个?
采纳答案by mlorbetske
Not tested, but I believe the code should look like this. Basically, we substitute a MemoryStreamand set its position back to 0after writing the fingerprint data into it so that the data may be read back and formatted for storage, leaving the rest of the code in tact (excepting for the name change)
没有经过测试,但我相信代码应该是这样的。基本上,我们在将指纹数据写入其中后MemoryStream,将其替换为 a并将其位置重新设置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 = "";
}

