Hi All,
My project is a standalone application with lots data retrieval and sometimes data update.
(No SQL server or connection provided)
Here is sample code
I used DataSet and DataTable to store dataCode:Dim objDS As New DataSet("Quesetion") Dim dtBook As DataTable = objDS.Tables.Add("Book") Dim dtChapter As DataTable = objDS.Tables.Add("Chpater") Dim objDR As DataRow With dtBook .Columns.Add("BookID", Type.GetType("System.Int32")) .Columns.Add("BookName", Type.GetType("System.String")) End With With dtChapter .Columns.Add("ChapterID", Type.GetType("System.Int32")) .Columns.Add("BookID", Type.GetType("System.Int32")) .Columns.Add("ChapterName", Type.GetType("System.String")) End With objDR = dtBook.NewRow() objDR("BookID") = 1 objDR("BookName") = "VB .Net" dtBook.Rows.Add(objDR) objDR = dtChapter.NewRow() objDR("ChapterID") = 1 objDR("BookID") = 1 objDR("ChapterName") = "Intro" dtChapter.Rows.Add(objDR) Dim expression As String = "ChapterName = 'Intro'" Dim foundRows() As DataRow = dtChapter.Select(expression) For Each tData As DataRow In foundRows Debug.Print(tData("BookID").ToString()) Next
It works fine when retrieve data from single table
But when retrieve data across multiple tables
e.g. Get the name of book with ChapterName = 'Intro'
Things get compacted.
Silly way to do so:
As DataTable.Select works only for that instance (which is very reasonable)Code:For Each tData As DataRow In foundRows expression = "BookID = " & tData("BookID").ToString() foundRows2 = dtBook.Select(expression) For Each tData2 As DataRow In foundRows2 Debug.Print(tData2("BookName").ToString()) Next Next
And seem DataSet doesn't have method like "Select"
Are there any way to retrieve data across multiple tables?
something like
SELECT BookName FROM Book, Chapter WHERE Book.BookID = Chapter.BookID AND Chapter.ChapterName = 'Intro'
OR should I use other data type / format to store the data ?
Thanks




Reply With Quote