When a barcode is scanned on form1, I make a call to database to get the item for this barcode and open form2 with pre-populated data.
If I use text changed event then it makes as many times as numbers in one barcode.
I cannot check length of the barcode as it may be different each time.
which event I should use to make only one call when Barcode is scanned?
I tried TextChanged, KeyPress, KeyDown events but they all are being called multiple times.
    private void txt_Barcode_TextChanged(object sender, EventArgs e)
    {
        con.Open();
        GenerateInvoice gn = new GenerateInvoice();
        string query = "SELECT * FROM dbo.Inventory WHERE Barcode = '" + txt_Barcode.Text + "' ";
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader dr = cmd.ExecuteReader();
        while (DR1.Read())
        {
            gn.txt_Barcode.Text = dr["Barcode"].ToString();
            gn.txt_ProductName.Text = dr["ProductName"].ToString();
            gn.txt_Price.Text = dr["SellingPrice"].ToString();
            gn.txt_QTY.Text = 1.ToString();
            gn.txt_Total.Text = dr["SellingPrice"].ToString();
        }
        con.Close();
    }
I am open to use textbox to capture barcode on form1 (I will hide it on UI)
 
     
    


 
    