Perhaps, your string cannot be converted to integer. What string are you passing? Since you are using the value of a textbox, it is likely to contain some non-numeric characters there, even a space can cause issues.
Also, change,
int val2 = 0;
val2 = 1 * ...
To the following,
int val2 = System.Convert.ToInt32(TextBox6.Text);
Even safer would be to use a
int.TryParse(string value, out int variable);
, which would look like the following,
int value;
if(int.TryParse(TextBox6.Text, out value)) {
} else {
}
Then you can write the code, and perform the rest of the stuff and add the parameter values to the query, then it would execute properly.
Int32.TryParse Method (String, Int32) (System)[
^]