Combining two results of datasets into one
Asked Answered
T

2

11

I have created a webservice which returns two datasets(return type) as results. Is it possible to combine two datasets results into one so that I can display it on one datalist? I try using arraylist but it returns nothing in datalist.

GetDepartureFlightsDetails() and getDepartureFlights() both returns a dataset values.

Below is the method i use to retrieve the webservice results.

public ArrayList GetDepartureFlightsDetails(String departurecountry, String arrivalcountry, DateTime departuredate)   
{
    DLSA datalayerTS = new DLSA();
    DLJS datalayerJW = new DLJS();

    ArrayList array = new ArrayList();

    array.Add(datalayerSA.GetDepartureFlightsDetails(departurecountry, arrivalcountry, departuredate));
    array.Add(datalayerJW.getDepartureFlights(departurecountry, arrivalcountry, departuredate));
    return array;
}
Traduce answered 2/1, 2013 at 6:33 Comment(3)
FredHomme change your declaration of array to something like this ArrayList arList = new ArrayList(); should would make it easy and more readable in regards to your return array not being confused as Array vs the return Type being of type ArrayList just a suggestionTangy
Ok. Sorry for the wrong naming.Traduce
just a suggestion FredHommeTangy
R
17

You can use the DataSet.Merge method:

firstDataSet.Merge(secondDataSet);

Update:

public DataSet GetDepartureFlightsDetails(String departurecountry, String arrivalcountry, DateTime departuredate)
{
    DLSA datalayerTS = new DLSA();
    DLJS datalayerJW = new DLJS();

    var firstDataSet = datalayerSA.GetDepartureFlightsDetails(departurecountry, arrivalcountry, departuredate));
    var secondDataSet = datalayerJW.getDepartureFlights(departurecountry, arrivalcountry, departuredate));
    firstDataSet.Merge(secondDataSet);

    return firstDataSet;
}
Roice answered 2/1, 2013 at 6:38 Comment(4)
careful about duplicate rows in new datatable when merging.Postage
how do i add the dataset results to a dataset? DataSet first = new DataSet(); Then?Traduce
The question says "GetDepartureFlightsDetails() and getDepartureFlights() both returns a dataset values", and I thought that means they return DataSets. That is not the case? What is the exact return type of those methods?Brockman
their return type is DataSet. so i put return GetDepartureFlightsDetails().Merge(getDepartureFlights()) ? but it returns a error "(Cannot implicitly convert type 'System.Data.DataSet'")"Traduce
S
0

Can't you make a wrapper Class and use List<> of the wrapper class , rather than Datasets.

Sandasandakan answered 2/1, 2013 at 6:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.