Quick review of the code, the error isn't where you indicated. How do I know - that exact line is assigning an integer a value. That's it. It is something inside your function GetCountScalar(SQL).
I am also not seeing a TRY CATCH block in there unless you are declaring that entire thing in the try catch which would be weird design principle and not even sure that'd work.
What I would do is toss in a breakpoint on this line:
ret = CInt(mySQLCommand.ExecuteScalar)
When that breakpoint gets hit, check the value of mySQLCommand; specifically looking at the value of CommandText. My expectation is that it is NULL. It SHOULDN'T be (as you are assigning it the value strSQL), but if it is coming back as NULL, you may want to go back a little bit in the code to this line:
Using mySQLCommand = New SqlCommand(strSQL, myConnection)
and check the value of strSQL. If that is NULL, then you will want to go back to this line:
iCount = GetCountScalar(SQL) //Error message point at the function in this line
and check the value of SQL as something is goofy there.
The error is pretty clear though - the value for CommandText (a property of a SqlCommand object) is not initialized and thus null. The question becomes "why is it not initialized?".
My coding habit is not to use the Using syntax as I find it more challenging to debug and I can clean things up myself (habit from my C coding days where you have to). But that is just a style thing; it shouldn't break your code.