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 IfEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: