Re: converting/casting before submitting

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Karl Seguin (_at_)
Date: 12/09/04


Date: Thu, 9 Dec 2004 17:19:06 -0500

SqlParameter.Value is of type Object, which suggest that everything is taken
care of internally and casting is indeed not required. Of course, to
confirm this assumption, we get Reflector and look at the disassembled code
for how SqlParameter.set_Value works.

We see that it calls something called SetTypeInfoFromComType which in turn
calls a static function GetMetaType of an internal class named MetaType.
This is the function that seems to be doing all the work..stuff like:

case TypeCode.DBNull:
   throw ADP.InvalidDataType(TypeCode.DBNull);
case TypeCode.Boolean:
  return MetaType.metaTypeMap[2];
case TypeCode.Char:
  throw ADP.InvalidDataType(TypeCode.Char);
case TypeCode.SByte:
  throw ADP.InvalidDataType(TypeCode.SByte);
case TypeCode.Byte
  return MetaType.metaTypeMap[20];
case TypeCode.Int16
 return MetaType.metaTypeMap[0x10];

Also, FIY, TinyInt is a value from 0-255, which in .Net maps to a Byte and
not an Int16.

Karl

-- 
MY ASP.Net tutorials
http://www.openmymind.net/
"djc" <noone@nowhere.com> wrote in message
news:%23cNeOYj3EHA.708@TK2MSFTNGP11.phx.gbl...
> I have typically always used one of the VB CType functions (not CType
itself
> but CInt, CString, etc...) to cast/convert an input value to its proper
type
> before passing it as a parameter to a SQL stored procedure. I recently
came
> accross one I did not know how to handle though... TinyInt. I have an SQL
> field of type TinyInt which is an 8bit integer. I came accross a ToInt16()
> vb function but not one for an 8 bit 'TinyInt'. So I next just went ahead
> and tried to submit the value as is to the stored procedure to see if
there
> would be a problem. The value is a string (from a
> dropdownListBox.SelectedItem.Text). To my suprise there was no error. It
> took the value fine. The SQL stored procedure was expecting a TinyInt as
> declared in the stored procedure. ??
>
> 1) Is there some type of auto-conversion in place? have I been wasting
time
> and/or slowing performance converting/casting myself all this time?
>
> 2) does the SQL stored procedure convert it itself since that is what was
> declared within it?
>
> any info would be greatly appreciated. Thanks.
>
>


Relevant Pages

  • Re: converting/casting before submitting
    ... Also, FIY, TinyInt is a value from 0-255, which in .Net maps to a Byte and ... So I next just went ahead> and tried to submit the value as is to the stored procedure to see if there> would be a problem. ... The SQL stored procedure was expecting a TinyInt as> declared in the stored procedure. ... have I been wasting time> and/or slowing performance converting/casting myself all this time? ...
    (microsoft.public.dotnet.framework.aspnet)
  • converting/casting before submitting
    ... I have typically always used one of the VB CType functions (not CType itself ... before passing it as a parameter to a SQL stored procedure. ... field of type TinyInt which is an 8bit integer. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Sort Numbers than send to DB?
    ... Here is the stored procedure, but I have not wrote any source code because I ... @Num1 tinyint, ... @Num6 tinyint ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Capturing SQL Stored Procedure Return Codes
    ... For a Recordset-returning Command: ... Returns a Recordset object reference or Nothing. ... My point is that I can force the SQL stored procedure to return a negative ... How do I capture return codes from a SQL Stored Procedure? ...
    (microsoft.public.access.modulesdaovba)
  • problem with different methods of invoking stored procedures through ADO
    ... parameters when calling an SQL stored procedure produce different ... the routine worked fine. ... adParamInput, 255, trim) ...
    (comp.databases.ms-access)