I have included a simple check for this function. You should always include null checks, parsing checks, etc. I suspect that either text box 1 or 2 sends some invalid data.
public void addqty() { int a, b; if (!int.TryParse(val1.Text, out a) || int.TryParse(val2.Text, out b)) result.Text = "Can't convert variable a or variable b"; else result.Text = (a + b).ToString(); } textBox1.Text = string.IsNullOrEmpty(row.Cells["Serial #"].Value.ToString()) ? "0" : row.Cells["Serial #"].Value.ToString(); textBox2.Text = string.IsNullOrEmpty(row.Cells["Barcode"].Value.ToString()) ? "0" : row.Cells["Barcode"].Value.ToString(); textBox3.Text = string.IsNullOrEmpty(row.Cells["Quantity"].Value.ToString()) ? "0" : row.Cells["Quantity"].Value.ToString();
source share