PC Review


Reply
Thread Tools Rate Thread

How to convert Type to DbType?

 
 
jiangyh
Guest
Posts: n/a
 
      28th Oct 2004
hi there :

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

thanks a lot.
jiangyh
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFkaHVbQyMtTVZQXQ==?=
Guest
Posts: n/a
 
      28th Oct 2004
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

 
Reply With Quote
 
jim.wiese@gmail.com
Guest
Posts: n/a
 
      11th Mar 2005
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">The 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.StringFixedLength:
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.AnsiString :
toReturn = typeof( string ) ;
break ;

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

case DbType.VarNumeric :
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert DataColumn.GetType() into a DbType or SqlDbType? Chris Bordeman Microsoft C# .NET 4 18th Nov 2006 04:48 AM
Converting between DbType and System.Type James Moore Microsoft ADO .NET 0 19th Sep 2004 10:28 PM
convert DbType to/from TypeCode richlm Microsoft ADO .NET 1 15th Jun 2004 10:09 AM
convert a Type to DBType ?! franky Microsoft Dot NET Compact Framework 2 9th Apr 2004 06:39 PM
How to convert System.Type to Data.DbType? Cepheus Microsoft ADO .NET 1 17th Mar 2004 09:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.