0

Hello All dear that is my second question there i am working on a project where i save employee fingerprints that is successfully saved but when i verifying from database using foreach loop it only verify first row record did not go through all rows for verification if there is multiple fingerprints it only verify only first record that i saved first not verify second record any suggestion to fix this please.

protected override void Process(DPFP.Sample Sample)
        {

            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT *FROM EmpRegistration", con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
          DataTable dt = new DataTable();
            sda.Fill(dt);
            con.Close();


            if (dt.Rows.Count > 0)
            {

                foreach (DataRow dr in dt.Rows)
                {
                    byte[] _img_ = (byte[])dr["Finger"];
                    MemoryStream ms = new MemoryStream(_img_);
                    DPFP.Template Template = new DPFP.Template();
                    Template.DeSerialize(ms);


                    DPFP.Verification.Verification Verificator = new DPFP.Verification.Verification();

                    con.Close();


                    base.Process(Sample);

                    // Process the sample and create a feature set for the enrollment purpose.
                    DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);

                    // Check quality of the sample and start verification if it's good
                    // TODO: move to a separate task
                    if (features != null)
                    {
                        // Compare the feature set with our template
                        DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                        Verificator.Verify(features, Template, ref result);
                        UpdateStatus(result.FARAchieved);

                        if (result.Verified)
                        {
                            MakeReport("Verified");

                        //try
                        //{
                        //    con.Open();
                        //    SqlDataReader myReader = null;
                        //    SqlCommand myCommand = new SqlCommand("select * from EmpRegistration",
                        //                                             con);

                        //    myReader = myCommand.ExecuteReader();
                        //    while (myReader.Read())

                        //    {
                        //        txtname.Text = myReader["EmpName"].ToString();
                        //        txtcnic.Text = myReader["CNIC"].ToString();

                        //    }
                        //    con.Close();
                        //}
                        //catch (Exception e)
                        //{
                        //    MessageBox.Show(e.ToString());
                        //}
                        //break;
                        break;
                        }
                        else if (result.Verified == false)
                        {
                            MakeReport("Employee Not Registered");
                        break;

                        }


                    }
                }
            }
        }
  • Possible duplicate of [Foreach loop follow only first row of data table in SQL Server in C# for fingerprint verification](https://stackoverflow.com/questions/52565628/foreach-loop-follow-only-first-row-of-data-table-in-sql-server-in-c-sharp-for-fi). This seems to be asking the same thing as your prior post; the code is largely the same except the `try ... catch` block has been commented out. – Lance U. Matthews Oct 03 '18 at 05:44

1 Answers1

0

In your for each loop, you test the first image. If it verified, you break. IF it is not verified, you break. The break stops the For Each loop, so you will never do more than the first one no matter which result you get.

DancingFool
  • 1,247
  • 1
  • 8
  • 10