473,513 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting an Object as an SqlDbType enumeration (possible)

Thanks to anyone in advance who can help :)

Ok, I know this is a far stretch, but what I'm trying to do is to cast a
System.object as one of the SqlDbType enumerations (SqlDbType.Int,
-.NVarchar, etc.) Is this anyway possible? Through inheritance, or anything?
Nov 16 '05 #1
1 3649
First, you can't cast to SqlDbType.Int or SqlDbType.NVarchar. SqlDbType is
an enumeration. Thus, SqlDbType.Int is a value, not a type.

If I understand what you're trying to do, I think you have an object
(presumably of a known type) that you would like to convert into the
equivalent type in the System.Data.SqlTypes namespace. This can be done
since all of the types in the System.Data.SqlTypes namespace have
constructors that have parameters that take the appropriate type in the
System namespace. For example, SqlInt32 takes an Int32 object as a
parameter. Note that these types do not correspond exactly with the
SqlDbType enumeration. For example when SqlDbType.NVarChar and
SqlDbType.VarChar are used, the appropriate type to use from the
System.Data.SqlTypes namespace is SqlString.

Hope this helps.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"studen77" <st******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
Thanks to anyone in advance who can help :)

Ok, I know this is a far stretch, but what I'm trying to do is to cast a
System.object as one of the SqlDbType enumerations (SqlDbType.Int,
-.NVarchar, etc.) Is this anyway possible? Through inheritance, or
anything?

Nov 16 '05 #2

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

Similar topics

3
2985
by: Matt | last post by:
Hi, Recently we had some code like this cause a failure: MyEnum myEnum = (MyEnum) (int) dt; i.e. reading an int out of the database and casting it into a type-safe enum. The thought...
11
4203
by: Vinod I | last post by:
Hi Team, I am having a string as "System.Data.SqlDbType.Int". Now I want to convert this string type to actual type to use with my Command object Parameter Creation. How I will convert this...
2
5376
by: babylon | last post by:
I have an enum public enum MyEnum : int { X, Y } I have to do int a = (int) MyEnum.X; can i overload the operator or other means to do something like
4
8347
by: Alicia | last post by:
Hi all, I have a problem with an Enum and Reflection. I am using an Xml and Reflection to create some controls, and to set their properties. All goes well until I encounter one property which is...
18
11300
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
7
2093
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
5
1128
by: Larry | last post by:
I get a "Specified cast is not valid" when excuting the following line in the subroutine below: spParm = spAddImage.Parameters("@fnameIn").Value = ckfile.Text I'm not sure what I'm doing...
0
1754
by: bborowin | last post by:
Hi there, Given a collection of SqlDbType enums (eg, {BigInt, VarChar, Bit}), I need to convert it to a collection of corresponding C# Types (here, {long, string, bool}). The contents of the...
0
1813
by: rbrowning1958 | last post by:
Hello, Trying to compile some code I was given. Vs 2005 patches applied AFAICT. Help / About reports visual studio versiopn 8.0.50727.867 and framework version 2.0.50727. Code references...
0
7267
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
7175
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
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7120
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
7542
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
5697
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,...
0
4754
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...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.