如何使用C#和PostgreSQL将转换后的指纹位图保存到数据库

时间:2019-04-24 03:16:00

标签: c# postgresql npgsql

我目前正在创建一个可以保存Digital Persona 4500中的生物识别指纹的软件

我已经将扫描的指纹转换为位图。使用Digital Persona提供的C#SDK

如何将其保存到数据库?使用NPGSQL和PostgreSQL

我已经有一个使用NPGSQL将字符串保存到数据库的程序。代码尚未完全完成

    public Form2()
    {
        InitializeComponent();
        cp2.StartCapture();
        cp2.EventHandler = this;
    }

    private void Form2_Load(object sender, EventArgs e)
    {

    }

    public void finger()
    {
        #region Form Event Handlers;
    }

    public void OnComplete(object Capture, string ReaderSerialNumber, Sample Sample)
    {
        sp2.ConvertToPicture(Sample, ref img2);

        fingerprint2.Image = img2;

    }



    public void OnFingerGone(object Capture, string ReaderSerialNumber)
    {
        img2 = null;
    }

    public void OnFingerTouch(object Capture, string ReaderSerialNumber)
    {
        img2 = null;
    }

    public void OnReaderConnect(object Capture, string ReaderSerialNumber)
    {

    }

    public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
    {

    }

    public void OnSampleQuality(object Capture, string ReaderSerialNumber, CaptureFeedback CaptureFeedback)
    {
        if (CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
            System.Diagnostics.Debug.WriteLine("Good");
        else
            System.Diagnostics.Debug.WriteLine("Bad");
    }

    private void Label1_Click(object sender, EventArgs e)
    {

    }


    #endregion

    private void Form2Closed(object sender, FormClosedEventArgs e)
    {
        cp2.StopCapture();
    }

    private void Save_register_Click(object sender, EventArgs e)
    {
        NpgsqlConnection dbcon = new NpgsqlConnection(connstring);
        dbcon.Open();

        NpgsqlCommand dbcmd = dbcon.CreateCommand();

        try
        {
            string sql1 = "INSERT INTO biometrics_details (user_id,biometrics_blob) VALUES ('" + UserIDBox.Text.ToString() + "')";

            dbcmd.CommandText = sql1;
            // commented the line below
            dbcmd.Parameters.Add("@image", NpgsqlTypes.NpgsqlDbType.Bytea);
            dbcmd.ExecuteNonQuery();
        }
        catch (NpgsqlException ex)
        {
            MessageBox.Show("there is a error");
            if (ex.Data == null)
            {
                throw;
            }
            else
            {

            }
        }
    }

0 个答案:

没有答案