Solved

How to append data to system.data.dataset.

Posted on 2011-03-25
3
679 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now