473,480 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

converting/casting before submitting

djc
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.
Nov 19 '05 #1
7 1610
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" <no***@nowhere.com> wrote in message
news:%2***************@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.

Nov 19 '05 #2
the sql sp declares the datatype. when you call the client libary, you pass
an object and tell the client lib the actual datatype of your data. the
client lib will then convert the datatype to the matching sqldatatype, and
pass sql datatype to the sqlserver. the sqlserver than converts the passed
sql datatype to the sp dataype if it can. see the sql Convert function doc's
to see the supported conversions.

-- bruce (sqlwork.com)
"djc" <no***@nowhere.com> wrote in message
news:%2***************@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.
|
|
Nov 19 '05 #3
My newsreader shows my reply to this as deleted...so I'll try again...sorry
for the possible double post:

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.
--
MY ASP.Net tutorials
http://www.openmymind.net/
"djc" <no***@nowhere.com> wrote in message
news:%2***************@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.

Nov 19 '05 #4
djc
Thank you for the excellently explained answer. I appreciate it greatly.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OM**************@TK2MSFTNGP10.phx.gbl...
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" <no***@nowhere.com> wrote in message
news:%2***************@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.


Nov 19 '05 #5
djc
My newsreader shows both posts... but since your original is showing deleted
to you I am thanking you in both places to make sure you get the proper
thanks. Thanks!

Thank you for the excellently explained answer. I appreciate it greatly.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%***************@TK2MSFTNGP11.phx.gbl...
My newsreader shows my reply to this as deleted...so I'll try again...sorry for the possible double post:

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.
--
MY ASP.Net tutorials
http://www.openmymind.net/
"djc" <no***@nowhere.com> wrote in message
news:%2***************@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.


Nov 19 '05 #6
djc
great! thank you!

"bruce barker" <no***********@safeco.com> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
the sql sp declares the datatype. when you call the client libary, you pass an object and tell the client lib the actual datatype of your data. the
client lib will then convert the datatype to the matching sqldatatype, and
pass sql datatype to the sqlserver. the sqlserver than converts the passed
sql datatype to the sp dataype if it can. see the sql Convert function doc's to see the supported conversions.

-- bruce (sqlwork.com)
"djc" <no***@nowhere.com> wrote in message
news:%2***************@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.
|
|

Nov 19 '05 #7
nedbalzer
1 New Member
I know this is an old and dormant thread, but can anyone tell me where the equivalences between SQL data types (int, datetime, varchar, nvarchar, text, etc.) and the ASP.NET parameter types (int32, String, etc.) are documented?

TIA.

-- Ned
Jun 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
13898
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
1
11613
by: Kent Lewandowski | last post by:
Hi, I saw this post from 3 years ago regarding converting DOUBLE values to CHAR in ibm DB2. Now I'm having the same problem. No real solution was posted to that old thread. Has anyone got...
2
1238
by: Frazer | last post by:
hi, I am confused when to use (int) and when to use Convert.toint32.. eg here string s= "1"; int j = (int) s; //this gives me an error and i have to use convert.toint32. why is that so and...
4
3170
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
2
1414
by: TheLongshot | last post by:
Ok, let's try this again. I have an ASP.NET 1.1 application that I'm working to convert to 2.0, but I've run into a snag. The problem is with this line: return...
6
2999
by: nanodust | last post by:
hello all i am relatively new to python, catching on, but getting stuck on simple thing: i have two string bytes i need to push into a single (short) int, like so in c: temp = strBuf;
35
34158
by: Sean Farrow | last post by:
Hi: What is best and safest way of converting a char* to a const char *? Can I use const_cast? Cheers Sean.
5
1911
by: Chad | last post by:
Keith made the following comment " You can convert an int*, or an int**, or an int***, or ... to void* without loss of information -- except that you lose the type information, which you have to...
9
4462
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.