-1

Good afternoon! I just want to ask if there's wrong with my code here? Especially in the streaming/database saving logic. This saves the same data into the database even if I use different fingerprints, which is (42-4D-2E-06-07-00-00-00-00-00). As I know, the data that is being saved should be different each finger. But even though I try all my fingers, the same data are being inputted into the db. Any help would be much appreciated.

Also, sorry if my question would look confusing, I'm a newbie here and I'm still trying to learn the proper ways. :)

        public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
        {

        Bitmap bitmap;
        bitmap = ConvertSampleToBitmap(Sample);
        Bitmap img = new Bitmap(bitmap, Picture.Size);
        this.Invoke(new Function(delegate ()
        {
            Picture.Image = img;   // fit the image into the picture box
                                   //string ping;
                using (MemoryStream m = new MemoryStream())
                {
                    img.Save(m, ImageFormat.Bmp);
                    m.Position = 0;
                    DPFP.Template Template = new DPFP.Template(m);
                    MemoryStream fingerprintData = new MemoryStream();
                    Template.Serialize(fingerprintData);
                    fingerprintData.Position = 0;
                    BinaryReader br = new BinaryReader(fingerprintData);
                    Byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);
                    string ping = BitConverter.ToString(bytes);

                    MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

                    connBuilder.Add("Server", "localhost");
                    connBuilder.Add("Port", "3306");
                    connBuilder.Add("Database", "db_fingerprint");
                    connBuilder.Add("Username", "root");
                    connBuilder.Add("Password", "");

                    MySqlConnection conn = new MySqlConnection(connBuilder.ConnectionString);

                    MySqlCommand cmd = conn.CreateCommand();

                    cmd.CommandText = "INSERT INTO tbl_finger VALUES(@finger_id,  @finger_tag, @stud_id)";
                    cmd.Parameters.AddWithValue("finger_id", "");
                    cmd.Parameters.AddWithValue("stud_id", txtstud_num.Text);
                    cmd.Parameters.AddWithValue("finger_tag", ping);

                    conn.Open();
                    int a = cmd.ExecuteNonQuery();
                    if (a > 0)
                    {
                        MessageBox.Show("Fingerprint Registered.");
                        cmd.CommandText = "UPDATE tbl_students SET is_registered = 1 WHERE stud_id = '" + txtstud_num.Text + "';";
                        cmd.ExecuteNonQuery();
                    }
                    else
                    {
                        MessageBox.Show("No Fingerprint Registered.");
                    }
                    conn.Close();
                }
        }));
    }
TheGeneral
  • 79,002
  • 9
  • 103
  • 141
Ghoenn Woods
  • 29
  • 1
  • 6
  • 1
    `WHERE stud_id = '" + txtstud_num.Text + "';"` Please don't do that. Use parameters like your earlier code. – mjwills Feb 16 '19 at 06:34
  • 1
    Is finger_id the column you are talking about? If yes I see you are passing empty to this. May be some default value being set at database side? – G_S Feb 16 '19 at 06:36
  • 1
    Maybe you read less than necessary. Try: ` Byte [] bytes = br.ReadAllBytes();` – Nikolaus Feb 16 '19 at 06:37
  • When you run this, what is the length of `ping.Length` with the first fingerprint? With the second? – mjwills Feb 16 '19 at 10:50
  • @G_S the finger_id is AI in the db. – Ghoenn Woods Feb 17 '19 at 15:30
  • @Nikolaus I'd try that. thanks :) – Ghoenn Woods Feb 17 '19 at 15:31
  • @mjwills they're all the same length. here is the actual length of the data *42-4D-86-7C-06-00-00-00-00-00-36-00-00-00-28-00-00-00-4A-01-00-00-42-01-00-00-01-00-20-00-00-00-00-00-00-00-00-00-C4-0E-00-00-C4-0E-00-00-00-00-00-00-00-00-00-00-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF* – Ghoenn Woods Feb 17 '19 at 15:43
  • What is the sample and what is the capture parameter? – Nikolaus Feb 17 '19 at 17:54
  • If you mean sample of data, it is that long binary lines above. the parameter of capture is bitmap, if I'm not mistaken that that is what you need.. – Ghoenn Woods Feb 17 '19 at 18:40

1 Answers1

0

It’s these lines of code:

bitmap = ConvertSampleToBitmap(Sample);
Bitmap img = new Bitmap(bitmap, Picture.Size);

You convert your sample to bitmap and add it to your db-Entity. Instead you should use the capture. As Capture is of object-type I don’t know, if you have to convert it, but the desired line could look like this:

Bitmap img = (Bitmap) Capture;

Edit: As I did further research, I realized, that my answer is wrong, but maybe you could use this Tutorial to find out, what your error could be.

Maybe you need to await your capture.

Nikolaus
  • 1,859
  • 1
  • 10
  • 16
  • thank you for this, Sire! So far, this is the best solution I had, though it still not fixing the error for it creates another error which is _Unable to cast object of type 'DPFP.Capture.Capture' to type 'System.Drawing.Bitmap_ I will try to fix this myself first then will just go back here when I need help again. But thank you for all your efforts to help. I am new to C# and you all are very great helps :) – Ghoenn Woods Feb 18 '19 at 14:52
  • @GhoennWoods I‘ve updated my answer. Maybe this helps you. – Nikolaus Feb 19 '19 at 12:56
  • Alright, I'll try this. Thank you very much for the helps, sire! – Ghoenn Woods Feb 19 '19 at 14:11