Hello Team
I want to add product to list in a textbox by earsching for the product or scanning the barcode before selling but when I tried to search for product it says connection not close.
private void txt_Search_Product_Barcode_KeyDown(object sender, KeyEventArgs e) {
try { if (txt_Search_Product_Barcode.Text == String.Empty) { return; } else { String _pcode; String _productname; Decimal _price; int qty; cn.Open(); cm = new SqlCommand("select * from tblProduct where Barcode like '" + txt_Search_Product_Barcode.Text + "'", cn); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { // validate product quantity to show avoid selling when product is out of stock
qty = int.Parse(dr["StockIn"].ToString()); _pcode = dr["PCode"].ToString(); _productname = dr["ProductName"].ToString(); _price = decimal.Parse(dr["SalesPrice"].ToString()); dr.Close(); cn.Close();
//ADDToLIST(_pcode, _price, _qty);
} else { dr.Close(); cn.Close(); }
}
} catch (Exception ex) { dr.Close(); cn.Close(); MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }