ARTICLE

How do I fill data in DataSet from multiple tables?

Posted by Praveen Kumar Articles | Visual Basic 2010 January 18, 2005
To fill a DataSet from multiple database tables, you fill different DataSet objects using different data adapters and call Merge method of DataSet.
 
Reader Level:

You can use Merge method of DataSet to merge other DataSet objects. To fill a DataSet from multiple database tables, you fill different DataSet objects using different data adapters and call Merge method of DataSet.

The following source code reads data from three database tables - Heading, SubHead, and Link, merge all data sets and view data in a DataGrid control.

Private connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=F:\C#\Magazine\Extranet.mdb"
Private conn As OleDbConnection = New OleDbConnection(connStr)
conn.Open()
Dim str As String = "SELECT * FROM Heading"
Dim da1 As OleDbDataAdapter = New OleDbDataAdapter(str, conn)
Dim ds1 As DataSet = New DataSet("Heading")
da1.Fill(ds1, "Heading")
Dim ds2 As DataSet = New DataSet("SubHead")
str = "SELECT * FROM SubHeading"
Dim da2 As OleDbDataAdapter = New OleDbDataAdapter(str, conn)
da2.Fill(ds2, "SubHeading")
Dim ds3 As DataSet = New DataSet("Link")
str = "SELECT * FROM Link"
Dim da3 As OleDbDataAdapter = New OleDbDataAdapter(str, conn)
da3.Fill(ds3, "Link")
ds1.Merge(ds2)
ds1.Merge(ds3)
dataGrid1.DataSource = ds1.DefaultViewManager
conn.Close()

share this article :
post comment
 

Usefull Code

Posted by asdfasdf asdfsdaf Jan 21, 2008
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
MOST LIKED ARTICLE
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor