Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
hi all i am facing a problem with a array response from a web service, i have invoked a webmethod which returns a collection of data in the form of arrays, now here what the problem is that when i checked the response i found that the array contains one more array in it, array with in array eg

--------Outer array-----------
array[0] = [countryname]
array[1] = [countryid]
array[2] = [locations] --> (location consists of multiple records)
array[3] = [issuccess]

here in the above example the
array[2] = [locations] has one more array in it

--------Inner array-----------
array[0] = [locationid]
array[1] = [locationname]
array[2] = [locationaddress]
array[3] = [locationphone]
array[4] = [issuccess]

please guide me how to bind the response in different datatable one datatable for outer array, and another datatable for inner array
Posted

1 solution

Hi,

Maybe the code below can help you.

class Program
  {
      static void Main(string[] args)
      {
          Object[] arrayInner = new object[5];
          arrayInner[0] = "1";
          arrayInner[1] = "Istanbul";
          arrayInner[2] = "Address";
          arrayInner[3] = "111111";
          arrayInner[3] = true;

          Object[] arrayOuter = new object[4];
          arrayOuter[0] = "Turkey";
          arrayOuter[1] = "90";
          arrayOuter[2] = arrayInner;
          arrayOuter[3] = true;

          DataTable dataTableForOuter = new DataTable();
          DataTable dataTableForInner = new DataTable();

          for (int i = 0; i < arrayOuter.Length; i++)
          {
              if (arrayOuter[i].GetType().IsArray)
              {
                  dataTableForInner.Columns.Add("InnerData", typeof(object));
              }
              else
              {
                  dataTableForOuter.Columns.Add("OuterData" + i, typeof(object));
              }
          }

      }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900