Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 782
  • 1.1k
  • 55.7k

No Mapping Exist

Apr 12 2024 7:59 PM

Hello Team, In my window application, tried updating data from the window form into the database and this is the error that is poping up, kindly assist.

 private void btnUpdate_Click(object sender, EventArgs e)
        {
             try
            {
                if (MessageBox.Show("Please confirm if you want to update item bought on credit?", "UPDATE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    
                    con.Open();
                    cmd = new SqlCommand("update tblOnCredit SET CDate=@Cdate,CDescription=@Cdescription,Qty=@Cqty,CSellingPrice=@CsellingPrice, CAmountPaid=@CamountPaid, CBalance=@Cbalance,CustomersName=@customername,Phone=@phone where CreditId like '" + id + "'", con);
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.Parameters.AddWithValue("@Cdate", dtStockInDate.Value.ToString("dd-MM-yyyy"));
                    cmd.Parameters.AddWithValue("@Cdescription", txtProduct.Text);
                    cmd.Parameters.AddWithValue("@Cqty", txtQuantity.Text);
                    cmd.Parameters.AddWithValue("@CsellingPrice", txtSellingPrice);
                    cmd.Parameters.AddWithValue("@CamountPaid", txtAmountPaid.Text);
                    cmd.Parameters.AddWithValue("@Cbalance", txtBalance.Text);
                    cmd.Parameters.AddWithValue("@customername", txtCustomersName.Text);
                    cmd.Parameters.AddWithValue("@phone", txtPhoneNo.Text);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    MessageBox.Show("This record has been successfully updated!", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();

                }
            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);

            }
        }
 

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentCell.OwningColumn.Name == "dgvEdit")
            {

                frmOnCreditSalesAdd frm = new frmOnCreditSalesAdd();
                frm.btnAdd.Enabled = false;
                frm.btnUpdate.Enabled = true;
                frm.id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["dgvID"].Value);
                frm.dtStockInDate.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvDate"].Value);
                frm.txtProduct.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvDescription"].Value);
                frm.txtSellingPrice.Text = Convert.ToDecimal(dataGridView1.CurrentRow.Cells["dgvSellingPrice"].Value).ToString("#0.00");
                frm.txtQuantity.Text = Convert.ToInt32(dataGridView1.CurrentRow.Cells["dgvQty"].Value).ToString();
                frm.txtAmountPaid.Text = Convert.ToDecimal(dataGridView1.CurrentRow.Cells["dgvAmountPaid"].Value).ToString("#0.00");
                frm.txtBalance.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvBalance"].Value);
                frm.txtCustomersName.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvCustomerName"].Value);
                frm.txtPhoneNo.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvPhoneNo"].Value);
                MainClass.BlurBackground(frm);
                LoadBoughtOnCreditRecord();
            }
            else if (dataGridView1.CurrentCell.OwningColumn.Name == "dgvDelete")
            {
                if (MessageBox.Show("Please confirm if you want to Delete this record?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {


                    con.Open();
                    cmd = new SqlCommand("delete from tblOnCredit where CreditId like '" + dataGridView1.Rows[e.RowIndex].Cells["dgvID"].Value.ToString() + "'", con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    MessageBox.Show("This record has been successfully deleted!", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadBoughtOnCreditRecord();
                }

            }

        }

 


Answers (3)