Add more data to a dataset VB.net

Hi ,

I want to add more data to an existing dataset table. The code bellow shows the current code I use to read ONE CSV into  a dataset table. I would like to create a loop to add more of the same type of CSV files to the same dataset table. What is the best way to achive this ?

Michal
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path.GetDirectoryName(TextName) & "\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""
        Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
        Dim da As OleDb.OleDbDataAdapter
        Dim ds As DataSet
 
        ' Try
        'Open Data Adapter to Read from Text file
        da = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & Path.GetFileName(TextName) & "]", objConn)
        ds = New DataSet()
 
        'Fill dataset using dataadapter
        da.Fill(ds, "Temp")

Open in new window

MichMatAsked:
Who is Participating?
 
wht1986Commented:
I assume you want to load other files in to the same table so something like

Dim da = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & Path.GetFileName(TextName) & "]", objConn)
 
da.ClearBeforeFill = false;
 
da.Fill(ds, "Temp")
 
da.SelectCommand.CommandText = ("SELECT * FROM [" & Path.GetFileName(OtherTextName) & "]";
 
da.Fill(ds, "Temp");
 
da.SelectCommand.CommandText = ("SELECT * FROM [" & Path.GetFileName(LastFileName) & "]";
 
da.Fill(ds, "Temp");

Open in new window

0
 
wht1986Commented:
You can even use the adapter over when you call fill on the same datatable.  There is a property call ClearBeforeFill on the adapter. Set it to false and it will leave what is there on the next fill and just append it.
0
 
MichMatAuthor Commented:
Im not sure how to arange the code to do this
0
 
MichMatAuthor Commented:
Hi ,

Thanks for the answer, you have the right idea about what I want to do , however Im getting an error,
ClearBeforefill is not a member of oledb.OleDBDataadapter.

What Can I do ?
0
 
wht1986Commented:
Bah sorry was thinking of the auto generated code of a dataset. It's tableadapter has that property.

You can also use the merge method of a dataset

DataSet1.Merge(DataSet2);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.