Hello Team,
When I try saving into the database it work perfectly but return this respond saying that input string was not in the correct format.
private void btn_Save_Click(object sender, EventArgs e) { if (txt_Productname.Text == "" || txt_CostPrice.Text == "" || txt_SalesPrice.Text == "") { MessageBox.Show("Missing Information !!!"); } else {
try { if (MessageBox.Show("Please confirm if you want to save this product?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { decimal Profit = Convert.ToDecimal(txt_SalesPrice.Text) - Convert.ToDecimal(txt_CostPrice.Text); cn.Open(); cm = new SqlCommand("INSERT INTO tblProduct(PCode,ProductDate,ProductName, Category, CostPrice,Profit,SalesPrice,Tax,TotalPrice,Barcode)VALUES(@pCode,@productDate,@productName, @category, @costPrice,@profit,@salesPrice,@tax,@totalPrice,@barcode)", cn); cm.Parameters.AddWithValue("@pCode", txt_ProductCode.Text); cm.Parameters.AddWithValue("@productDate", DbType.Date).Value = dtProductDate.Value; cm.Parameters.AddWithValue("@productName", txt_Productname.Text); cm.Parameters.AddWithValue("@category", cbo_Category.Text); cm.Parameters.AddWithValue("@costPrice", txt_CostPrice.Text); cm.Parameters.AddWithValue("@profit", Profit); cm.Parameters.AddWithValue("@salesPrice", txt_SalesPrice.Text); cm.Parameters.AddWithValue("@tax", cbo_Tax.Text); cm.Parameters.AddWithValue("@totalPrice", txt_TotalPrice.Text); // cm.Parameters.AddWithValue("@stockIn", txt_Stock.Text); cm.Parameters.AddWithValue("@barcode", txt_Barcode.Text); cm.ExecuteNonQuery(); cn.Close(); MessageBox.Show("Product has been successfully saved!", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); fm.LoadCategory();
} } catch (Exception ex) { cn.Close(); MessageBox.Show(ex.Message); } } }
and
private void cbo_Tax_SelectedIndexChanged(object sender, EventArgs e) { try { decimal salesPrice = decimal.Parse(txt_SalesPrice.Text); decimal tax = decimal.Parse(cbo_Tax.Text); decimal total = (salesPrice * tax / 100) + salesPrice; txt_TotalPrice.Text = total.ToString("#,##0.00"); } catch (Exception ex) { throw ex; } }