Add Get Response Stream data to dataset

I have a process that runs, passes in a single variable  and gets a response from a web service and loads that into a dataset.

Partial code is attached.

I now have to do this in a for each manner.

So what I would like to do is APPEND each incoming response to the dataset and keep everything in one table.

So that if I fed in 20 seperate "single" requests from my list, I can bind to a grid with this code which uses my dataset

Dim dt As DataTable
 dt = New DataTable()
 dt = ds.Tables(0)
Blah...blah..blah...

            ' Get response   
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Load data into a dataset   
            ds = New DataSet()
            ds.ReadXml(response.GetResponseStream())

Blah...blah...blah...

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
 
CodeCruiserCommented:
Declare a class level dataset

Dim MainDataset As New DataSet

Then load the dataset with the first values so that it has all the structure.

Afterwards do this

            ds = New DataSet()
            ds.ReadXml(response.GetResponseStream())

            MainDataSet.Tables(0).Merge(ds.Tables(0))
0
 
volkingCommented:
I think this is what you need.
Understand the below is PSEUDO code that you'll need to change to fit your needs.

Imports System.Data
Imports System.Data.SqlClient

        Dim ds As DataSet = New DataSet()
        ds.Tables.Add(New DataTable("MyTable"))

        ds.Tables("MyTable").Columns.Add(New DataColumn("ColString", System.Type.GetType("System.String")))
        ds.Tables("MyTable").Columns.Add(New DataColumn("ColInt32", System.Type.GetType("System.Int32")))
        ds.Tables("MyTable").Columns.Add(New DataColumn("ColDecimal", System.Type.GetType("System.Decimal")))

        For Each ?Record?
            Dim newRow As DataRow = ds.Tables("MyTable").NewRow()
            newRow.Item("ColString") = Record.STRING?
            newRow.Item("ColInt32") = Record.INTEGER?
            newRow.Item("ColDecimal") = Record.DECIMAL?
        Next

Open in new window


When the loop is done you're built a dataset dynamically in memory
0
 
Larry Bristersr. DeveloperAuthor Commented:
Sorry for the late get-back
Perfect...thanks
0
 
CodeCruiserCommented:
Glad to help :-)
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.