Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

Foreach loop follow only first row of data table in SQL Server in C# for fingerprint verification

That is my first question here I am currently working on an project Biometric attendance system and I am stuck at the place the fingerprints are saved in the database and when I retrieve fingerprints for verification and it retrieves only first record not others rows of datatable please help me in this regard.

This is my code:

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);

    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;
                }
                else if (result.Verified == false)
                {
                    MakeReport("Employee not registered");
                }
            }
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It actually goes through all records, but after the loop ends you just have the last record deserialized.

After Deserializing each record, you must use a Validator to check the validity of the finger print.

Have a look at How to verify Finger print template with the SQL Server


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...