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

How to Serialize-Deserialize the fingerprint of DigitalPersona u.ere.u 4500 in C# and saved to a database

你能帮帮我吗? 我想在 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>

它应该是口蹄疫,但我不能return它的原始形式。

作为 return 到它的正常形状?

string x = Fmd.SerializeXml(fmd);

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

检索字符串并传入

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

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

在我的例子中使用 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);