Quote:
Int32.Parse(myCommand3.ExecuteScalar().ToString());
This statement is a potential source of many exceptions, you have to handle them properly.
You stated your query is OK, but neverthless such code fails. Use the debugger to locate the problem (e.g. invalid textual representation of a
Int32
).