Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: beginner
Dec 9, 2002

GetOleDbType - Retrieving the OleDbType for the specified system type

' Return the OleDbType that represents the specified system type
' This is particularly useful when you have a DataTable and want to create a 
' OleDbParameter for onw of its columns, but don't know its type. 
' DataColumnName.DataType returns a Type, and you can convert it to OleDbType 
' by passing it to this function.
' Note: requires System.Data.OleDb
' Example:
'   Dim param As New OleDbParameter("TestCol", GetOleDbType(String))
Private Function GetOleDbType(ByVal sysType As Type) As OleDbType
    If sysType Is GetType(String) Then
        Return OleDbType.VarChar
    ElseIf sysType Is GetType(Integer) Then
        Return OleDbType.Integer
    ElseIf sysType Is GetType(Boolean) Then
        Return OleDbType.Boolean
    ElseIf sysType Is GetType(Date) Then
        Return OleDbType.Date
    ElseIf sysType Is GetType(Char) Then
        Return OleDbType.Char
    ElseIf sysType Is GetType(Decimal) Then
        Return OleDbType.Decimal
    ElseIf sysType Is GetType(Double) Then
        Return OleDbType.Double
    ElseIf sysType Is GetType(Single) Then
        Return OleDbType.Single
    ElseIf sysType Is GetType(Byte()) Then
        Return OleDbType.Binary
    ElseIf sysType Is GetType(Guid) Then
        Return OleDbType.Guid
    End If
End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap