471,570 Members | 937 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

FormatException & Data.SqlClient.SqlCommand

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 ***
Jan 8 '06 #1
2 1720
I think Exceptions are used to give a General Error, instead of giving a
Specified Error (depends upon the Type of Exception u r using). Go down the
hieracrhy to the Format Exception Type, that can give you some useful
information

--
ALI RAZA SHAIKH
MCAD.net

alirazashaikh.blogspot.com
www.programmersparadise.cjb.net
"vooose" <no****@microsoft.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
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 ***

Jan 8 '06 #2
>Go down the hieracrhy to the Format Exception Type, that >can give you
some useful information

Such as? FormatException appears to have no extra information.
--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Jan 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by DC Gringo | last post: by
reply views Thread by cms3023 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.