private void btnUpdate_Click(object sender, EventArgs e) { try { con = new OleDbConnection(cs); con.Open(); string cb = "Update Stock set ConfigID=" + txtConfigID.Text + ",Quantity=" + txtQty.Text + ",Totalprice=" + txtTotalPrice.Text + ",StockDate= #" + dtpStockDate.Value + "# where StockID='" + txtStockID.Text + "'"; cmd = new OleDbCommand(cb); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); btnUpdate.Enabled = false; GetData(); frmMainMenu frm = new frmMainMenu(); frm.GetData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtProductname.Text == "") { MessageBox.Show("Please retrieve product name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProductname.Focus(); return; } if (txtQty.Text == "") { MessageBox.Show("Please enter quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtQty.Focus(); return; } try { con = new OleDbConnection(cs); con.Open(); String ct = "select ConfigID from stock where ConfigID=" + txtConfigID.Text +""; cmd = new OleDbCommand(ct); cmd.Connection = con; rdr = cmd.ExecuteReader(); if (rdr.Read()==true) { MessageBox.Show("Record already exists" + "\n" + "please update the stock of product", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if ((rdr != null)) { rdr.Close(); } return; } auto(); con = new OleDbConnection(cs); con.Open(); string cb = "insert into Stock(StockID,ConfigID,Quantity,Totalprice,StockDate) VALUES ('" + txtStockID.Text + "'," + txtConfigID.Text + "," + txtQty.Text + "," + txtTotalPrice.Text +",#" + dtpStockDate.Value + "#)"; cmd = new OleDbCommand(cb); cmd.Connection = con; cmd.ExecuteReader(); con.Close(); MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); btnSave.Enabled = false; GetData(); frmMainMenu frm = new frmMainMenu(); frm.GetData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }