Mapping a DataTable to an Object Class. Like a homemade Linq to SQL. Send over WCF to SilverLight

Application Foundation

An application I work has architecture in a way where we have a Class object that represents each table. So for example we might have a “Customer” table in the database. So our class would be something like..

Customer.vb class file…

Public Class Customer

    Private _FirstName As String = String.Empty
    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Private _LastName As String = String.Empty
    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

End Class

In this class is a function to say list all customers, we call this “GetList” method. You might use another way to bring back a list of data. Ideally now we’d want to bring back Enumerable Lists, but the app was already structured for DataSets and DataTables. So I was trying to reuse what we had.

Customer.vb class file

Public Function GetList() As Data.DataTable
    Dim oDS As Data.DataSet
    Try
        oDS = DataAccess.SqlHelper.ExecuteDataset(_ConnectionString, Data.CommandType.StoredProcedure, "CustomerGetList")
        Return oDS.Tables(0)
    Catch ex As Exception
        Throw ex
    Finally
        oDS = Nothing
    End Try
End Function

So on our pages we might do something like this…

Default.aspx.vb

Protected Sub Button1_ClickSave()
    Dim oCustomer As New Customer
    oCustomer.FirstName = "Fred"
    oCustomer.LastName = "Mastro"
    oCustomer.SaveToDB()

    GridView1.DataSource = oCustomer.GetList()
    GridView1.DataBind()

    oCustomer = Nothing

End Sub

 

And this returns a nice DataTable and populates the grid. Great!

Problem Areas over WCF to SliverLight

I was working on a SilverLight application that would talk to an existing business application, to pull back and list records.  I had to use a Service, so I went with WCF since RIA.Net is not in production yet.  The problem was that DataTables can not be serialized and set over WCF to SilverLight.  So I tried messing with Linq to SQL to pull data back and populate classes I already had, but LinqTables are not serializable either, and instead of modifying all the Linq classes generated in my class I wanted to find an easier solution.

DataTable to List(Of Customer) Solution

I can across these two posts: Datatable to List of Objects Mapper and Creating datarow to object mapper and was amazed. Using reflection Chris Rock (lol) was able to read the properties of the object and map each column of the datatable to the desired property of the object. This is what I’m looking to do.  This would manually mimic Linq type functionality. The Bulk of the code is this

My Helper.vb class file

  1.  
  2. Public Class Helper
  3.  
  4.     Public Function MapDatarowToObject(Of T)(ByVal dr As DataRow) As T
  5.         Try
  6.  
  7.             If dr Is Nothing Then
  8.                 Return Nothing
  9.             End If
  10.  
  11.             Dim instance As T = Activator.CreateInstance(Of T)()
  12.  
  13.             Dim properties() As Reflection.PropertyInfo = instance.GetType().GetProperties()
  14.  
  15.             If (properties.Length > 0) Then
  16.                 For Each propertyObject As Reflection.PropertyInfo In properties
  17.  
  18.                     Dim valueSet As Boolean = False
  19.  
  20.                     For Each attributeObject As Object In propertyObject.GetCustomAttributes(False)
  21.  
  22.                         If attributeObject.GetType() Is GetType(MapperColumn) Then
  23.                             Dim columnAttributeObject As MapperColumn = CType(attributeObject, MapperColumn)
  24.  
  25.                             If (columnAttributeObject.ColumnName <> String.Empty) Then
  26.  
  27.                                 If dr.Table.Columns.Contains(columnAttributeObject.ColumnName) AndAlso Not dr(columnAttributeObject.ColumnName) Is DBNull.Value Then
  28.                                     propertyObject.SetValue(instance, dr(columnAttributeObject.ColumnName), Nothing)
  29.                                     valueSet = True
  30.  
  31.                                 End If
  32.  
  33.                             End If
  34.                         End If
  35.                     Next
  36.  
  37.                     If Not valueSet Then
  38.                         If dr.Table.Columns.Contains(propertyObject.Name) AndAlso Not dr(propertyObject.Name) Is DBNull.Value Then
  39.                             propertyObject.SetValue(instance, dr(propertyObject.Name), Nothing)
  40.                         End If
  41.                     End If
  42.  
  43.                 Next
  44.             End If
  45.  
  46.             Return instance
  47.         Catch ex As Exception
  48.             Throw ex
  49.         End Try
  50.     End Function
  51.  
  52.     Public Function MapDataTableToList(Of T)(ByVal dt As DataTable) As Collections.Generic.IList(Of T)
  53.         If dt Is Nothing Then
  54.             Return Nothing
  55.         End If
  56.  
  57.         Dim list As IList(Of T) = New List(Of T)
  58.  
  59.         For Each dr As DataRow In dt.Rows
  60.             list.Add(MapDatarowToObject(Of T)(dr))
  61.         Next
  62.  
  63.         Return list
  64.     End Function
  65.  
  66. End Class
  67.  
  68. <AttributeUsage(AttributeTargets.Property)> _
  69. Public Class MapperColumn
  70.     Inherits Attribute
  71.  
  72.     Private mColumnName As String
  73.  
  74.     Public Sub New(ByVal columnName As String)
  75.         mColumnName = columnName
  76.     End Sub
  77.  
  78.     Public Property ColumnName() As String
  79.         Get
  80.             Return mColumnName
  81.         End Get
  82.         Set(ByVal value As String)
  83.             mColumnName = value
  84.         End Set
  85.     End Property
  86.  
  87. End Class

Using Mapper in WCF

Now in my WCF Service methods I can just instantiate Customers like I always do in the normal application and apply the new Mapper method to get a List of the class objects.

WCFServiceMethods.vb file (which is code-behind to WCFServiceMethods.svc)

  1. Imports System.ServiceModel
  2. Imports System.ServiceModel.Activation
  3. Imports System.Runtime.Serialization 'For DataContract
  4. Imports System.Collections.Generic
  5.  
  6. <ServiceContract(Namespace:="")> _
  7. <ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _
  8. <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
  9. Public Class WCFServiceMethods
  10.     <OperationContract()> _
  11.     Public Function GetCustomers() As Collections.Generic.List(Of Customer)
  12.         Dim oCustomer As New Customer
  13.  
  14.         Dim Customers As Collections.Generic.List(Of Customer)
  15.         Customers = Helper.MapDataTableToList(Of Customer)(oCustomer.GetList())
  16.  
  17.         oCustomer = Nothing
  18.         Return Customers
  19.  
  20.     End Function
  21. End Class

You’ll see in Line 15, I can take the DataTable and now create a List(Of Customer) object, which is serializable and send it over the wire.

Applying it in SilverLight or Other Application that uses your WCF Service

Assuming you referenced your WCF Service.. Now on my SilverLight app on a button click I can get the List of Customers and show it natively in a datagrid.

MainPage.xaml code-behind

Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSearch.Click
    Dim oWCFProxy As New WCFService.WCFServiceClient

    AddHandler oWCFProxy.GetCustomers, AddressOf oWCFProxy_GetCustomersCompleted
    oWCFProxy.GetCustomersAsync()

    oWCFProxy = Nothing

End Sub

Private Sub oWCFProxy_GetCustomersCompleted(ByVal sender As Object, ByVal e As WCFService.GetCustomersCompletedEventArgs)
    Dim Customers As Collections.ObjectModel.Collection(Of oWCFProxy.Customer)
    Customers = e.Result

    DataGrid1.ItemsSource = Customers
End Sub

Problem Area With Mapper Casting Types and Solution

So with all that above you should have enough to re-create all this. Read through Chris’ posts because it does a good job of explaining the mapper.  I ran into a problem with the mapper though on line 39. Problem is when it tries to map data from the database, it all comes back as a string, and you don’t know until run-time what System.Type you need, so you can’t CType or DirectCast by using System.Type.GetType(), so I had to create a crappy function to Throw ex check every possible combination. This the best way? I sure hope it isn’t. Hope to find a better solution for it but was pressed for time.

So what was my crappy solution? I don’t even want to post it haha. I swapped out line 39 and 28 with the a call to this method of 1531 lines of code.

Private Sub TryCastTypeToPropertyType(ByRef propertyObject As Reflection.PropertyInfo, ByRef instance As Object, ByRef dr As DataRow, ByRef ColumnName As String)

Try
'Try to Default Types
propertyObject.SetValue(instance, dr(ColumnName), Nothing)
Catch exDefault1 As InvalidCastException
Try
'Try to String
propertyObject.SetValue(instance, CType(dr(ColumnName), String), Nothing)
Catch exString1 As InvalidCastException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
Catch exString2 As ArgumentException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
End Try
Catch exDefault2 As ArgumentException
Try
'Try to String
propertyObject.SetValue(instance, CType(dr(ColumnName), String), Nothing)
Catch exString1 As InvalidCastException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
Catch exString2 As ArgumentException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
End Try
End Try
End Sub

Maybe I’ll get lucky and someone will post up a “Oh you can just do this, which is new in .Net 3.5 or 4.0.. “ and I can get rid of this thing. But hey it works!

Resource: How to Consume WCF and ASP.Net Web Services in Silverlight

Comments are closed