Solved

How to append data to system.data.dataset.

Posted on 2011-03-25
3
686 Views
Last Modified: 2012-06-27
I have a large group of Excel files that are my data source for a vb.net application.  I use OleDb to extract the relevant data from each spreadsheet (one row of data per spreadsheet).

My end product will be a table with each one of those data rows from above.

I need help figuring out how to dump the data into a single vb.net DataSet.  (I don't really understand details about TableMappings and DataSet.)

The code below works fine for single iteration, but I need to uncomment the "for loop" and get everything into the dataset and datagridview.  Can someone help?
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

DtSet = New System.Data.DataSet

#For Each xMarket in MarketArray
Dim xMarket = "Atlanta"
	MyConnection = New System.Data.OleDb.OleDbConnection _
		("provider=Microsoft.ACE.OLEDB.12.0;" & _
		" Data Source='" xMarket & ".xlsx" & "'; " & _
		" Extended Properties=" + Convert.ToChar(34).ToString() +
		"Excel 12.0;HDR=Yes" + Convert.ToChar(34).ToString())
	MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & myTab & "$] where Week like '%" & xWeek & "%'", MyConnection)
	MyCommand.TableMappings.Add("Table", "TestTable")
	MyCommand.Fill(DtSet)
	DataGridView1.DataSource = DtSet.Tables(0)
#Next

Open in new window

0
Comment
Question by:motokent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Chandan_Gowda earned 250 total points
ID: 35219042
you can use dataset merge method. Please follow the below link
http://aspalliance.com/148
0
 
LVL 10

Assisted Solution

by:khan_webguru
khan_webguru earned 250 total points
ID: 35219222
Hello Bro!

You can use this approach

 
Sub BindGrid()
     Dim myConnection as New SqlConnection (strConn)
 
     Dim DS1 As DataSet
     Dim DS1 As DataSet
     Dim MyCommand As SqlDataAdapter
 
     MyCommand = new SqlDataAdapter("exec s_get_table1", MyConnection)
     DS1 = new DataSet()
     MyCommand.Fill(DS1, "MyTable")
 
     MyCommand = new SqlDataAdapter("exec s_get_table2", MyConnection)
     DS2 = new DataSet()
     MyCommand.Fill(DS2, "MyTable")

     ds1.merge(ds2)
 
     MyDataGrid.DataSource=DS1.tables(0).DefaultView
     MyDataGrid.DataBind()
End Sub

Open in new window


Hope this will provide you some idea

Regards,

Asif Ahmed KHan
0
 

Author Closing Comment

by:motokent
ID: 35219315
Thank you both.  (The solutions were the same.)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question