The exception message is self explanatory and since we can not see your data or debug we can suggest you that the error is at one of the lines where you parse to
int
(totally 4 lines where you call Parse on
int
, where you should put the breakpoint).
Additionally you could use TryParse and assign value if it is parsed and then you will see where is your missing value (the one that makes trouble).
You can also make use of ternary operator in order not to bloat the code like this:
int tmpInt;
int.TryParse(StudentCode.Text, out tmpInt)??Comm.Parameters["@Code"].Value = tmpInt;
Comm.Parameters["@Code"].Value = int.TryParse(StudentCode.Text, out tmpInt)?tmpInt:-1;
Happy coding.