如何在C#中序列化 - 反序列化DigitalPersona u.ere.u 4500的指纹并保存到数据库

时间:2016-04-18 16:10:04

标签: c# mysql fingerprint

你可以帮帮我吗? 我想在mysql上保存指纹,这是我使用的代码。

private void enrollment_OnEnroll(DPCtlUruNet.EnrollmentControl enrollmentControl, DataResult<Fmd> result, int fingerPosition)
    {
        if (enrollmentControl.Reader != null)
        {
            ShowMessage("OnEnroll:  " + enrollmentControl.Reader.Description.Name + ", finger " + fingerPosition);
        }
        else
        {
            ShowMessage("OnEnroll:  lector no conectado, finger " + fingerPosition);
        }

        if (result != null && result.Data != null)
        {
            //valor de la huella serializada

            string valores = Fmd.SerializeXml(result.Data);
            MySqlConnection conexion = new MySqlConnection(_sender.cadena);
            String sql = String.Format("insert into cliente (clave_cuenta, huella) values('{0}','{1}')", textBox1.Text, valores );
            MySqlCommand comando = new MySqlCommand(sql, conexion);         
            try {
                conexion.Open();
                comando.ExecuteNonQuery();
                conexion.Close();
                MessageBox.Show("La huella se guardo satisfactoriamente","Almacenada",buttons:MessageBoxButtons.OK);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                throw;
            }
            conexion.Close();
            _sender.Fmds.Add(fingerPosition, result.Data);                

        }

        btnCancel.Enabled = false;

       // _sender.btnApruebaCompra.Enabled = true;
    }

这存储在mysql

<?xml version="1.0" encoding="UTF-8"?><Fid><Bytes>Rk1SACAyMAAA8gAz/v8AAAFlAYgAxADEAQAAAFYjQIEAZmBkQIEARl5kQMoBKE1jgM8BA0RhgMwAg0tcgNYAZKZcQIIBFB5bgOYA00FaQM8BQFVZQKAAtV9YgLUBEVFYgGUApXNWQOQBIkRUQL0A00RUgPoAckxTQLQAeKVTgG4AcwRTQQMAoKFSQMsA5ptQgMsA65tQQFAAk2xQQREAq0dQgHkA0RhOQEYAoxdCgI8A7Hg/gOEBP00+QFUA4B48gEoAwnQ6QJkA3aA2gJwBAXU2AQMA7UE1AJ0BE2szAQgA7EEuAJwBDqwtAQ4AY6MqAAA=</Bytes><Format>1769473</Format><Version>1.0.0</Version></Fid>

它应该是口蹄疫,但我无法将其恢复原状。

恢复正常状态?

2 个答案:

答案 0 :(得分:2)

string x = Fmd.SerializeXml(fmd);

将x作为字符串存储在数据库中。

检索字符串并传入

Fmd val = Fmd.DeserializeXml(从数据库中检索字符串);

使用 val 与您当前的输入进行比较。

答案 1 :(得分:0)

在我的情况下,使用Fmd.DeserializeXml()给了我这个错误

    '\' is an unexpected token. The expected token is '"' or '''. Line 1, position 15

所以我分别使用以下代码进行序列化和反序列化

     Fid.SerialiseXml(CaptureResult.data);

     Fid.DeserializeXml(xml string retrieved from db);