private void mtUpdate_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Do you want to update?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr.ToString() == "Yes") { if (String.IsNullOrEmpty(txtname.Text) || String.IsNullOrEmpty(txtqty.Text) || String.IsNullOrEmpty(txtprice.Text) || String.IsNullOrEmpty(txtstatus.Text) || String.IsNullOrEmpty(txtdes.Text) || comboBox1.Text == "") { MessageBox.Show("Check if all the fields are filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { String name = txtname.Text; int price = Convert.ToInt32(txtprice.Text); int qty = Convert.ToInt32(txtqty.Text); String status = txtstatus.Text; String des = txtdes.Text; int sup = comboBox1.SelectedIndex; DBItem di = new DBItem(); int line = di.updateItem(no, name, price, qty, status, des, u_id, sup, System.DateTime.Now.ToShortDateString()); if (line == 1) { MessageBox.Show("Data entered successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); SqlDataAdapter da; DBItem i = new DBItem(); da = i.getItem(); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } catch (Exception) { MessageBox.Show("Error , please try again", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
private void Items_Load(object sender, EventArgs e) { try { SqlDataAdapter da; DBItem i = new DBItem(); da = i.getItem(); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; DBSupplier s = new DBSupplier(); SqlDataReader DR; DR = s.getSupplier(); while (DR.Read()) { comboBox1.Items.Add(DR[0]); } } catch (Exception) { MessageBox.Show("Please fill out all the fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }