2 Replies Latest reply: Jun 1, 2012 11:07 AM by Iain Bruce RSS

Converting an IrfcStructure to datagrid.

Iain Bruce
Currently Being Moderated

Hi,

 

Im having a bit of difficulty gettign data retrieved as a IrfcStructure correctly formatted in to a asp datagrid. When bound to the grid, the data binds to vertically to a column with many rows (as opposed to one row with columns for each field). as well as this, it creates on column per row it creates with each column repeating the data again and again.

 

I have had success with binding Irfctbles, but it seems that structures are my nemisis!.

 

Any ideas anyone?

 

Many thanks

  • Re: Converting an IrfcStructure to datagrid.
    Case Ahr
    Currently Being Moderated

    Try dumping the structure to a datatable and binding the datatable.  Rough untested example below

     

                Dim rowTable As New DataTable

                For i As Integer = 0 To sapStructure.ElementCount - 1

                    rowTable.Columns.Add(sapStructure.GetElementMetadata(i).Name)

                Next

                Dim row As DataRow = rowTable.NewRow()

                For j As Integer = 0 To sapStructure.ElementCount - 1

                    row(j) = sapStructure.GetValue(j)

                Next

  • Converting an IrfcStructure to datagrid.
    Iain Bruce
    Currently Being Moderated

    Thank you for the pointer - just to confirm if anyone else needs to do this:

     

    this is the method I am now successfully using (C#)

     

    public DataTable ConvertStructure(IRfcStructure myrefcTable)  //Convert RFCStructure to datatable

            {

                DataTable rowTable = new DataTable();

                for (int i = 0; i <= myrefcTable.ElementCount - 1; i++)

                {

                    rowTable.Columns.Add(myrefcTable.GetElementMetadata(i).Name);

                }

                DataRow row = rowTable.NewRow();

                for (int j = 0; j <= myrefcTable.ElementCount - 1; j++)

                {     

                    row[j] = myrefcTable.GetValue(j);

                }

                rowTable.Rows.Add(row);

                return rowTable;

    }

     

     

    Call this method in your code by using:

     

    IRfcStructure customerTable = bapiCheckCustomer.GetStructure("BAPI_NAME");

    dataGridView1.DataSource = ConvertStructure(customerTable);