Solved

How to append data to system.data.dataset.

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

25 Experts available now in Live!

Get 1:1 Help Now