Click here to Skip to main content
16,015,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have This Class

Public Class PersonVO
Inherits ClientVO

Private _PersonFirstName As String
Private _PersonLastName As String
Private _PersonMiddleName As String


Public Property PersonFirstName() As String
Get
Return _PersonFirstName
End Get

Set(ByVal value As String)
_PersonFirstName = value
End Set
End Property


Public Property PersonLastName() As String
Get
Return _PersonLastName
End Get

Set(ByVal value As String)
_PersonLastName = value
End Set
End Property


Public Property PersonMiddleName() As String
Get
Return _PersonMiddleName
End Get

Set(ByVal value As String)
_PersonMiddleName = value
End Set
End Property

End Class


I Want to convert to Datatable or Dataset so i can easly saved in my Sql Database
Posted

 
Share this answer
 
Comments
Ahmad Al Halabi 11-Sep-13 4:15am    
>SetPersonDetails(Person)


>
Public Shared Function SetPersonDetails(ByVal PersonDetailsList As List(Of PersonVO)) As DataTable
Dim dt As New DataTable()
Try
dt.TableName = "Person"

For Each [property] As PropertyInfo In PersonDetailsList(0).[GetType]().GetProperties()
dt.Columns.Add(New DataColumn([property].Name, [property].PropertyType))
Next

For Each vehicle As PersonVO In PersonDetailsList
Dim newRow As DataRow = dt.NewRow()
For Each [property] As PropertyInfo In vehicle.[GetType]().GetProperties()
newRow([property].Name) = vehicle.[GetType]().GetProperty([property].Name).GetValue(vehicle, Nothing)
Next
dt.Rows.Add(newRow)
Next
Return dt
Catch ex As Exception
Console.WriteLine(ex.ToString())
Return Nothing
End Try
End Function
....
I am tring this solution, but it is give an error on : SetPersonDetails(Person)

Value of type 'TravelAgency.PersonVO' cannot be converted to 'System.Collections.Generic.List(Of TravelAgency.PersonVO)'
I Found The Solution
----------------------------

Public Shared Function SetPersonDetails(ByVal PersonDetailsList As PersonVO) As DataTable
Dim dt As New DataTable()
Try
dt.TableName = "Person"

For Each [property] As PropertyInfo In PersonDetailsList.[GetType]().GetProperties()
dt.Columns.Add(New DataColumn([property].Name, [property].PropertyType))
Next


Dim newRow As DataRow = dt.NewRow()
For Each [property] As PropertyInfo In PersonDetailsList.[GetType]().GetProperties()
newRow([property].Name) = PersonDetailsList.[GetType]().GetProperty([property].Name).GetValue(PersonDetailsList, Nothing)
Next
dt.Rows.Add(newRow)
Return dt
Catch ex As Exception
Console.WriteLine(ex.ToString())
Return Nothing
End Try
End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900