Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 852
  • 838
  • 37.6k

C# window application

Sep 16 2023 11:53 PM

Hello Team,

am developing a C# window application to scan product barcode and when i tried to scan the Barcode i get this error which says 

and this is my code please

private void txtPSearch_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if(txtPSearch.Text == String.Empty)
                {
                    return;
                }else
                {
                    String _pcode;
                    double _price;
                    int _qty;
                    cn.Open();
                    cm = new SqlCommand("select * from tblProduct where barcode like '" + txtPSearch.Text + "'", cn);
                    dr = cm.ExecuteReader();
                    dr.Read();
                    if (dr.HasRows)
                    {                   
                        frmQty frm = new frmQty(this);                                                  
                        qty = int.Parse(dr["qty"].ToString());
                        _pcode = dr["pcode"].ToString();
                        _price = double.Parse(dr["price"].ToString());
                        _qty = int.Parse(txtQty.Text);                       
                        dr.Close();
                        cn.Close();
                        frm.ShowDialog();
                        AddToCart(_pcode, _price, _qty);
                       
                    }
                    else
                    {
                        dr.Close();
                        cn.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                cn.Close();
                MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
       


Answers (6)