FormatException & Data.SqlClient.SqlCommand

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Consider executing a stored procedure which has a single INT arg:

SqlCommand command = new SqlCommand("Some_Stored_Procedure", conn);
command.CommandType =
CommandType.StoredProcedure; command.Parameters.Add("@UserID",
SqlDbType.Int); command.Parameters["@UserID"].Value = "150a";
command.ExecuteReader();

You receive the message "System.FormatException: Input string was not in
a correct format"

I would have expected something *slightly* more useful eg "For Parameter
'@UserID' the format '150a' is invalid".

Is this information hidden somewhere in the Exception object - or do I
have to print out each Parameter/Value of the SQLCommand and figure it
out myself?

Regards



--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
.


Quantcast