473,782 Members | 2,531 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 3664
First, you can't cast to SqlDbType.Int or SqlDbType.NVarc har. 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.Sql Types namespace. This can be done
since all of the types in the System.Data.Sql Types 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.NVarC har and
SqlDbType.VarCh ar are used, the appropriate type to use from the
System.Data.Sql Types namespace is SqlString.

Hope this helps.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"studen77" <st******@discu ssions.microsof t.com> wrote in message
news:7E******** *************** ***********@mic rosoft.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
3009
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 behind this construct was to enforce type safety and
11
4240
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 string to the type object ?. Thanks in advance
2
5392
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
8361
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 defined like this: public enum MyType { Alpha = 0, Beta = 1 }
18
11370
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
2141
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 following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
5
1151
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 wrong to cause this error. I'm using the following to set up this parameter: spParm = spAddImage.Parameters.Add("@fnameIn", SqlDbType.VarChar, 256)
0
1796
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 source collection is not known ahead of time; it could be any valid combination of enums in the SqlDbType enumeration. Short of writing an explicit switch statement for all elements in the
0
1830
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 SqlDbType.date and receives compilation error that the enumeration does not contain a definition for Date. I looked at the definition and sure enough my enumeration ends with:
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7492
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.