Hi Tim!I will throw some ideas of what I have done here to get "types". Maybe it can help you.
To get a System.Type of a SqlDBType:
''' <summary>
''' Find out the SqlDbType of a System.Type variable
''' </summary>
''' <param name="theType"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetDBType(ByVal theType As System.Type) As SqlDbType
Dim p1 As SqlClient.SqlParameter
Dim tc As System.ComponentModel.TypeConverter
p1 = New SqlClient.SqlParameter()
tc = System.ComponentModel.TypeDescriptor.GetConverter(p1.DbType)
If tc.CanConvertFrom(theType) Then
p1.DbType = CType(tc.ConvertFrom(theType.Name), DbType)
Else
'Try brute force
Try
p1.DbType = CType(tc.ConvertFrom(theType.Name), DbType)
Catch ex As Exception
'Do Nothing
End Try
End If
Return p1.SqlDbType
End Function
To find out a Column type, in order to set defaults:
'-- set default value
Dim lb As Byte
lb = CType(0, Byte)
Select Case columnType.ToString
Case "System.String"
col.DefaultValue = ""
Case "System.Int32"
col.DefaultValue = CType(0, Integer)
Case "System.Boolean"
col.DefaultValue = False
Case "System.Decimal"
col.DefaultValue = CType(0, Decimal)
Case "System.Byte"
col.DefaultValue = CType(0, Byte)
Case "System.DateTime"
col.DefaultValue = "1800-01-01 00:00:00.000"
End Select
To convert a System.Data.DbType into a System.Type:
Public Shared Function GetSystemType(ByVal DbType As System.Data.DbType) As System.Type
'-- establish locals
Dim stType As System.Type = GetType(System.String)
'-- test the sent DbType
Select Case DbType
Case Data.DbType.String, Data.DbType.AnsiString, Data.DbType.AnsiStringFixedLength, _
Data.DbType.StringFixedLength
stType = GetType(System.String)
Case Data.DbType.Int32
stType = GetType(System.Int32)
Case Data.DbType.Boolean
stType = GetType(System.Boolean)
Case Data.DbType.Decimal, Data.DbType.Currency
stType = GetType(System.Decimal)
Case Data.DbType.Byte, Data.DbType.SByte
stType = GetType(System.Byte)
Case Data.DbType.Date, Data.DbType.DateTime, Data.DbType.DateTime2
stType = GetType(System.DateTime)
End Select
'-- return converted System.Type
Return stType
End Function