473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a Specific Object - System.Data.SqlDbType.Int

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
Nov 15 '05 #1
11 4202
Hi,

Type myType = Type.GetType("System.Data.SqlDbType.Int");

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Vinod I" <Vi****@PMAM.com> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
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


Nov 15 '05 #2
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
Type myType = Type.GetType("System.Data.SqlDbType.Int");


That won't work for two reasons:

1) System.Data.SqlDbType.Int isn't a type. System.Data.SqlDbType is a
type (an enumeration, in fact) and Int is a member of the enumeration.

2) Type.GetType ("System.Data.SqlDbType") will return null anyway,
because the type lives in System.Data.dll, not mscorlib or the assembly
the code will be running in. You need to specify the full assembly name
to get types from other assemblies.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Hi,

Do let me know how to tackle the situation.

Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
Type myType = Type.GetType("System.Data.SqlDbType.Int");


That won't work for two reasons:

1) System.Data.SqlDbType.Int isn't a type. System.Data.SqlDbType is a
type (an enumeration, in fact) and Int is a member of the enumeration.

2) Type.GetType ("System.Data.SqlDbType") will return null anyway,
because the type lives in System.Data.dll, not mscorlib or the assembly
the code will be running in. You need to specify the full assembly name
to get types from other assemblies.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
Vinod I <Vi****@PMAM.com> wrote:
Do let me know how to tackle the situation.


Well, we'll need a bit more information. Is it *always* going to be one
of the SqlDbTypes? If not, is there some range it'll be in?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Hi,

It will be always of "SqlDBTypes". At runtime I will be getting the type
information as "String" and I want to add parameters to my command object
accordingly. Please let me know the solution as early as possible.

Thanks
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Vinod I <Vi****@PMAM.com> wrote:
Do let me know how to tackle the situation.


Well, we'll need a bit more information. Is it *always* going to be one
of the SqlDbTypes? If not, is there some range it'll be in?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6
Vinod I <Vi****@PMAM.com> wrote:
It will be always of "SqlDBTypes". At runtime I will be getting the type
information as "String" and I want to add parameters to my command object
accordingly. Please let me know the solution as early as possible.


In that case, just strip off the bit before the last dot (or just get
your uses to pass "Int" instead) and use
Enum.Parse(typeof(SqlDbTypes), name)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
> That won't work for two reasons:

1) System.Data.SqlDbType.Int isn't a type. System.Data.SqlDbType is a
type (an enumeration, in fact) and Int is a member of the enumeration.
Agree with that. It's me being lazy not to look up in MSDN (I don't use ADO
..NET in the recent months). Apologies to the original poster.
2) Type.GetType ("System.Data.SqlDbType") will return null anyway,
because the type lives in System.Data.dll, not mscorlib or the assembly
the code will be running in. You need to specify the full assembly name
to get types from other assemblies.
I thought that since System.Data.dll was already loaded to the application
domain, type resolution wouldn't need specifying the assembly name. It's
never late to learn!

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m... Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
Type myType = Type.GetType("System.Data.SqlDbType.Int");


That won't work for two reasons:

1) System.Data.SqlDbType.Int isn't a type. System.Data.SqlDbType is a
type (an enumeration, in fact) and Int is a member of the enumeration.

2) Type.GetType ("System.Data.SqlDbType") will return null anyway,
because the type lives in System.Data.dll, not mscorlib or the assembly
the code will be running in. You need to specify the full assembly name
to get types from other assemblies.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #8
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
2) Type.GetType ("System.Data.SqlDbType") will return null anyway,
because the type lives in System.Data.dll, not mscorlib or the assembly
the code will be running in. You need to specify the full assembly name
to get types from other assemblies.


I thought that since System.Data.dll was already loaded to the application
domain, type resolution wouldn't need specifying the assembly name. It's
never late to learn!


It's a pain that there isn't a way of doing basically that. Of course,
System.Data.dll may not have been loaded yet - the assembly isn't (as I
understand it) loaded until it's first actually referenced.

If you try this program:

using System;
using System.Data;
using System.Threading;

class MainClass
{
static void Main(string[] args)
{
Console.WriteLine ("Hello, world.");
Thread.Sleep(5000);
OtherClass.DoSomethingDataRelated();
Thread.Sleep(5000);
}
}

class OtherClass
{
public static void DoSomethingDataRelated()
{
// Quick way of avoiding inlining without
// remembering the attribute name to do it
// properly :)
if (DateTime.Now.Ticks==0)
throw new Exception();

DataSet ds = new DataSet();
}
}

from Visual Studio, watching the Output window, you'll see a 5 second
pause between the start and when the data (and related) assemblies are
loaded.

You can load all referenced assemblies by looking at
Assembly.GetReferencedAssemblies() and loading them recursively. You
could *then* call GetType on each of the assemblies in turn until you
find the right one. Bit grotty though :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
Hi,

I think that will solve my problem. But if possible, please let me know
the exact synatax .
I tryed like below. But not working,
objCmd.Parameters.Add(objDRTmp["ParamName"].ToString(),
Enum.Parse(typeof(SqlDbType), "Int"), intSize)

Thank U.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Vinod I <Vi****@PMAM.com> wrote:
It will be always of "SqlDBTypes". At runtime I will be getting the type information as "String" and I want to add parameters to my command object accordingly. Please let me know the solution as early as possible.


In that case, just strip off the bit before the last dot (or just get
your uses to pass "Int" instead) and use
Enum.Parse(typeof(SqlDbTypes), name)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #10
Thanks Budy.... I solved the Problem. I have to cast it again, Like,

(SqlDbType) Enum.Parse(typeof(SqlDbType), "Int")
Once Again Thanks for the guidence.

"Vinod I" <Vi****@PMAM.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
Hi,

I think that will solve my problem. But if possible, please let me know
the exact synatax .
I tryed like below. But not working,
objCmd.Parameters.Add(objDRTmp["ParamName"].ToString(),
Enum.Parse(typeof(SqlDbType), "Int"), intSize)

Thank U.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Vinod I <Vi****@PMAM.com> wrote:
It will be always of "SqlDBTypes". At runtime I will be getting the type information as "String" and I want to add parameters to my command object accordingly. Please let me know the solution as early as possible.


In that case, just strip off the bit before the last dot (or just get
your uses to pass "Int" instead) and use
Enum.Parse(typeof(SqlDbTypes), name)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #11
Vinod I <Vi****@PMAM.com> wrote:
I think that will solve my problem. But if possible, please let me know
the exact synatax .
I tryed like below. But not working,
objCmd.Parameters.Add(objDRTmp["ParamName"].ToString(),
Enum.Parse(typeof(SqlDbType), "Int"), intSize)


Sorry - you'll need to cast the result of Enum.Parse to SqlDbType:

SqlParameter param = new SqlParameter
(objDRTmp["ParamName"].ToString(),
(SqlDbType)Enum.Parse(typeof(SqlDbType), "Int"),
intSize);

objCmd.Parameters.Add(param);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12

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

Similar topics

0
9743
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
1
3646
by: studen77 | last post by:
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,...
0
1552
by: Dica | last post by:
i'm getting an error when trying set my dataAdapter's selectCommand. the sqlStatement is a storedProc which takes parameters, so it's constructed as: sqlSelectCommand1.CommandText = ""; ...
0
1892
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
0
2117
by: Roman | last post by:
I'm trying to create the form which would allow data entry to the Client table, as well as modification and deletion of existing data rows. For some reason the DataGrid part of functionality stops...
1
1588
by: Manuel Canas | last post by:
Hello there, I am using the VB.NET Standart Edition compiler and I would like to know if this is not supported on this edition. This is just a testing code from a book that I'm trying here and...
1
2750
by: tedqn | last post by:
Problem: - Stored procedure input parameters data type specific (SqlDbType.Int, SqlDbType.VarChar,etc). - Form submitted value in TextBox, DropDownList, etc are all string type (I guess). Some...
1
1622
by: KhoaNguyen | last post by:
i have two classes..one is a base and the other is inherited from the base class Below is my code -------ConnectionProvider class--------------------- using System; using...
2
2408
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
0
7216
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
7098
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
7303
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,...
0
7367
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
7018
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
7471
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...
1
5028
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
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.