mutlyp
October 25th, 2011, 03:39 PM
Hope someone can help me with this I just can't get my head around it.
I got this code off the net:
---------------------------------------------------------------------------------------------
Public Class Book
Private m_Name As String
Private m_Chapters As List(Of Chapter)
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
Public Property Chapters() As List(Of Chapter)
Get
Return m_Chapters
End Get
Set(ByVal value As List(Of Chapter))
m_Chapters = value
End Set
End Property
End Class
Public Class Chapter
Private m_Title As String
Private m_Page As String
Public Property Title() As String
Get
Return m_Title
End Get
Set(ByVal value As String)
m_Title = value
End Set
End Property
Public Property Page() As String
Get
Return m_Page
End Get
Set(ByVal value As String)
m_Page = value
End Set
End Property
End Class
Public Sub New()
InitializeComponent()
Dim books As New ObservableCollection(Of Book)()
For i As Integer = 0 To 4
Dim book As New Book() With {.Name = "Book" + i.ToString()}
book.Chapters = New List(Of Chapter)()
For j As Integer = 0 To 4
book.Chapters.Add(New Chapter() With {.Title = "Chapter" + i.ToString() + "_" + j.ToString()})
Next
books.Add(book)
Next
Me.MainList.ItemsSource = books
End Sub
----------------------------------------------------------------------------------------------------
As you can see there is a List(Of Chapter)
And in the code it is populated with Hard Codeing "Chapter" into book.Chapters.Add
I need to know how do you do this with data from a SQL Database table.
So if I had two tables in a database one called Books and the other called Chapters
Books
BookID1 Book1
BookID2 Book2
Chapters
ChapterID1 BookID1 Chapter1
ChapterID2 BookID1 Chapter2
ChapterID3 BookID2 Chapter1a
ChapterID4 BookID2 Chapter2a
ChapterID5 BookID2 Chapter3a
How do I get this data into the List(of )?
Please help
thank you
I got this code off the net:
---------------------------------------------------------------------------------------------
Public Class Book
Private m_Name As String
Private m_Chapters As List(Of Chapter)
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
Public Property Chapters() As List(Of Chapter)
Get
Return m_Chapters
End Get
Set(ByVal value As List(Of Chapter))
m_Chapters = value
End Set
End Property
End Class
Public Class Chapter
Private m_Title As String
Private m_Page As String
Public Property Title() As String
Get
Return m_Title
End Get
Set(ByVal value As String)
m_Title = value
End Set
End Property
Public Property Page() As String
Get
Return m_Page
End Get
Set(ByVal value As String)
m_Page = value
End Set
End Property
End Class
Public Sub New()
InitializeComponent()
Dim books As New ObservableCollection(Of Book)()
For i As Integer = 0 To 4
Dim book As New Book() With {.Name = "Book" + i.ToString()}
book.Chapters = New List(Of Chapter)()
For j As Integer = 0 To 4
book.Chapters.Add(New Chapter() With {.Title = "Chapter" + i.ToString() + "_" + j.ToString()})
Next
books.Add(book)
Next
Me.MainList.ItemsSource = books
End Sub
----------------------------------------------------------------------------------------------------
As you can see there is a List(Of Chapter)
And in the code it is populated with Hard Codeing "Chapter" into book.Chapters.Add
I need to know how do you do this with data from a SQL Database table.
So if I had two tables in a database one called Books and the other called Chapters
Books
BookID1 Book1
BookID2 Book2
Chapters
ChapterID1 BookID1 Chapter1
ChapterID2 BookID1 Chapter2
ChapterID3 BookID2 Chapter1a
ChapterID4 BookID2 Chapter2a
ChapterID5 BookID2 Chapter3a
How do I get this data into the List(of )?
Please help
thank you