473,770 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert Type to DbType?

hi there :

I have a question about how to convert Type to DbType?

thanks a lot.
jiangyh
Nov 16 '05 #1
2 29513
Hi,

You don't need to do explicit conversion from Type to SqlType for example
Int32 to SqlInt32.

SqlInt32 sqlint;
int i = 20;

sqlint = i; // no explicit conversion required...

It is automatically taken care for you by the SqlType. The SqlType
implements implicit operator overloading to take for the same.

Hope that helps...

Regards,
Madhu

MVP - C# | MCSD.NET

"jiangyh" wrote:
hi there :

I have a question about how to convert Type to DbType?

thanks a lot.
jiangyh

Nov 16 '05 #2
I'm not sure why someone hasn't written this, but here is goes:

(no warranties, expressed or implied)
/// <summary>
/// Get the native type based on the database type
/// </summary>
/// <param name="dbType">T he database type to convert</param>
/// <returns>The equivalent managed type, otherwise the DBNull
type</returns>
static Type ConvertType( DbType dbType )
{
Type toReturn = typeof( DBNull ) ;

switch( dbType )
{
case DbType.String:
toReturn = typeof( string ) ;
break ;

case DbType.UInt64 :
toReturn = typeof( UInt64 ) ;
break ;

case DbType.Int64 :
toReturn = typeof( Int64 ) ;
break ;

case DbType.Int32:
toReturn = typeof( Int32 ) ;
break ;

case DbType.UInt32:
toReturn = typeof( UInt32 ) ;
break ;

case DbType.Single:
toReturn = typeof( float ) ;
break ;

case DbType.Date:
toReturn = typeof( DateTime) ;
break ;

case DbType.DateTime :
toReturn = typeof( DateTime ) ;
break ;

case DbType.Time :
toReturn = typeof( DateTime ) ;
break ;

case DbType.StringFi xedLength:
toReturn = typeof( string ) ;
break ;

case DbType.UInt16:
toReturn = typeof( UInt16 ) ;
break ;

case DbType.Int16:
toReturn = typeof( Int16 ) ;
break ;

case DbType.SByte:
toReturn = typeof( byte ) ;
break ;

case DbType.Object:
toReturn = typeof( object ) ;
break ;

case DbType.AnsiStri ng :
toReturn = typeof( string ) ;
break ;

case DbType.AnsiStri ngFixedLength :
toReturn = typeof( string ) ;
break ;

case DbType.VarNumer ic :
toReturn = typeof( decimal) ;
break ;

case DbType.Currency :
toReturn = typeof( double ) ;
break ;

case DbType.Binary :
toReturn = typeof( byte[] ) ;
break ;

case DbType.Decimal :
toReturn = typeof( decimal ) ;
break ;

case DbType.Double:
toReturn = typeof( Double ) ;
break ;

case DbType.Guid :
toReturn = typeof( Guid ) ;
break ;

case DbType.Boolean :
toReturn = typeof( bool ) ;
break ;
}

return toReturn ;
}

jiangyh wrote:
hi there :

I have a question about how to convert Type to DbType?

thanks a lot.
jiangyh


Nov 16 '05 #3

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

Similar topics

4
12803
by: Davor | last post by:
This is what I want to do: int currentWord = 0; currentWord++; textBoxOtherLang.Text = orginalLanguage; But, I get a "Cannot implictly convert type 'char' to 'string'" error when trying to do it. How do I fix it? Thanks!
22
27898
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = (( curRow == System.DBNull.Value ) ? SqlInt32.Null : (int)curRow ); The errors are (in turn):
14
29518
by: Chris | last post by:
Hi, I try to print out truth-tables for an &&-operation using the following code, unfortunatly I get compiler errors : for ( byte i1=0; i1<=1; i1++) { for ( byte i2=0; i2<=1; i2++) { bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
2
6739
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text = "Username already exists!" Else lblStatus.Text = "Success!"
9
10530
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient: objMailMessage.To = dtrRecipient; I'm not sure why I am getting this error. Below is the complete code I am working with.
6
14567
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web server. I am able to log in. However after publishing the page to my local IIS, it results in the below error. This error is occurring on the Visual Studio.Net 2k5 release version, but did not occur on the beta 2, same code. A point of interest, is...
6
30194
by: John | last post by:
The following code: int test = 1; bool isTrue = (bool)test; results in a compiler error: Cannot convert type 'int' to 'bool' wtf, any ideas on how to work around this?
7
2484
by: =?Utf-8?B?RWl0YW4=?= | last post by:
What would be the "right" way to convert type 'byte' to 'string'? Thanks EitanB
2
4501
by: ransaj | last post by:
objCompanyRequirement.Salary = Convert.ToInt32 (txtCRF_Salary.Text); cannot implicitly convert type 'int' to 'string' objCompanyRequirement.InterviewDate = Convert.ToDateTime(txtCRF_InterviewDate.Text); cannot implicitly convert type 'System.DateTime' to 'string'
0
9617
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
10099
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...
0
8929
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
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
6710
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
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
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
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.