Re: Why aren't data types in SqlParameters validated?
- From: "Rad [Visual C# MVP]" <nospam@xxxxxxxxxx>
- Date: Tue, 27 Feb 2007 03:40:01 +0300
On Mon, 26 Feb 2007 02:17:32 -0500, Jerad Rose wrote:
I believe this question is simple enough -- why aren't data types in
SqlParameters validated in ADO.NET?
For example, why is an exception *not* thrown on this line:
cmd.Parameters.Add(New SqlParameter("@Id", Data.SqlDbType.Int)).Value = "not
an int"
Ideally, this wouldn't even compile, let alone execute. But it's even worse
that this line will execute, only later to bomb out when the stored proc is
executed, giving me this error:
Failed to convert parameter value from a String to a Int32.
Which can lead you on a wild goose chase tracking down the one out of
possibly several parameters that had a type issue.
My next question is, if the data type parameter in this constructor is not
for the sake of type safety, what is its purpose?
Lastly, is there anything that can be done (within reason) to ensure type
safety when setting parameter values, so that an exeption is thrown on the
line where the parameter value was attempted to be set? If not, what is the
best practice for accomplishing type safety when setting up store procedures
in ADO.NET?
Just FYI, this is in reference to ADO.NET 2.0.
Thanks in advance for your feedback.
Jerad
Probably because stored procedures have the same behavior and will try to
convert data types during execution ...
Also, it would be difficult to enforce if some of the parameters being
passed is a user defined data type
--
Bits.Bytes
http://bytes.thinkersroom.com
.
- References:
- Why aren't data types in SqlParameters validated?
- From: Jerad Rose
- Why aren't data types in SqlParameters validated?
- Prev by Date: Re: quetion about identity, dataadapter
- Next by Date: Re: Why aren't data types in SqlParameters validated?
- Previous by thread: Re: Why aren't data types in SqlParameters validated?
- Next by thread: quetion about identity, dataadapter
- Index(es):
Relevant Pages
|