private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { txtCountUpDown.ResetText(); ItemTotalTxt.Clear(); String text = listBox1.GetItemText(listBox1.SelectedItem); itemNameTxt.Text = text; String sql = "select price from item where name = '" + text + "'"; SqlDataAdapter daa = new SqlDataAdapter(sql, dataAccess.connection); DataSet ds = new DataSet(); daa.Fill(ds); try { itemPriceTxt.Text = ds.Tables[0].Rows[0][0].ToString(); } catch (Exception) { } dataAccess.Dispose(); }
private void addCartBtn_Click(object sender, EventArgs e) { if (ItemTotalTxt.Text != "0" && ItemTotalTxt.Text != "") { n = dataGridView1.Rows.Add(); dataGridView1.Rows[n].Cells[0].Value = itemNameTxt.Text; dataGridView1.Rows[n].Cells[1].Value = itemPriceTxt.Text; dataGridView1.Rows[n].Cells[2].Value = txtCountUpDown.Value; dataGridView1.Rows[n].Cells[3].Value = ItemTotalTxt.Text; total += int.Parse(ItemTotalTxt.Text); grandTotalTxt.Text = "Tk " + total; txtCountUpDown.ResetText(); ItemTotalTxt.Clear(); itemNameTxt.Clear(); itemPriceTxt.Clear(); } else { MessageBox.Show("Minimum Quantity need to be 1", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }