Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 780
  • 1.1k
  • 55.6k

String is not in correct format

Nov 18 2023 2:51 PM

Hello Team,

Am having this error in my code 

private void UpdateItem()
{
    int NewQty = Stock - Convert.ToInt32(txtQuantity.Text);
        
    try
    {                                  
            con.Open();
            cmd = new SqlCommand("update tblItem SET ItQty=@Qty where ItId=@PKey", con);
           //cmd.Parameters.AddWithValue("@id", id);                    
            cmd.Parameters.AddWithValue("@Qty", NewQty);
            cmd.Parameters.AddWithValue("@PKey", ProdKey);                 
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("This Product has been successfully addedd!", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                           
    }
    catch (Exception ex)
    {
        con.Open();
        MessageBox.Show(ex.Message);
    }
}

int ProdKey = 0;
int Stock = 0;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{       
         txtProductName.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["dgvName"].Value);
        Stock = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[3].Value.ToString());             
        txtSellingPrice.Text = Convert.ToDecimal(dataGridView1.CurrentRow.Cells["dgvSellingPrice"].Value).ToString("#0.00");                           
       
    if(txtProductName.Text =="")
    {
        ProdKey = 0;
    }
    else
    {
        ProdKey = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
    }
}


Answers (11)