0

I have the below code which reads in an IMEI number from a textbox and uses the value to search an accessDB for the corresponding row of data to display in a datagridview.

I don't have a search button the app just searches for it once the number goes in (always 15 digits).

My problem is that for some IMEI numbers there are more than one row of data with that IMEI.

Sometimes only one row of data is returned instead of 3. It just takes the first instance it finds which is often an overridden version and is deleted by checkDeleted().

How can I get it to keep searching?

The checkDeleted() method checks for if the row is Overridden and removes that row.

private void txtScannedValue_TextChanged(object sender, EventArgs e)
    {
        if (txtScannedValue.Text.Length == 15)
        {
            conn1.Open();

            OleDbCommand cmd1 = new OleDbCommand("Select * from TBL where IMEI=@param1", conn1);
            cmd1.Parameters.AddWithValue("@param1", txtScannedValue.Text);
            OleDbDataReader reader1;
            reader1 = cmd1.ExecuteReader();

            DataTable dt = new DataTable();
            dt.Load(reader1);

            if (dt.Rows.Count > 0)
            {
                if (dataGridView1.DataSource != null)
                {
                    ((DataTable)dataGridView1.DataSource).ImportRow(dt.Rows[0]);
                    checkDeleted();
                }
                else
                {
                    dataGridView1.DataSource = dt;
                }
            }
            else
            {
                MessageBox.Show("No Data Found");
            }

            //reset textBox
            txtScannedValue.Text = "";

            conn1.Close();
        }
    }

example database

IMEI Deleted
1234 Overriden
1234 Overriden
1234 Current
5678 Overriden
5678 Current
2
  • It is not clear what is in your table, but from the table you show, if there is a Deleted field, then couldn’t you just add that to you query? Something like… "Select * from TBLTest3 where IMEI=@param1 AND Deleted = 'Current'", conn1); Commented Jan 27, 2022 at 15:39
  • Aagh... Thank you for pointing out. Commented Jan 27, 2022 at 15:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.