Skip to Content
author's profile photo
Former Member

.NET function ToADODataTable does not work

Hi,

We need help on using SAPTable.ToADODataTable and

SAP.Table.FromADODataTable methods

DataTables are used extensively in our application, and we need to get the data or structure (as in the example below) from an SAPTable, modify it, and pass it back to

SAP.

In SAP .NET Connector 1.0 manual it is stated that for

FromADODataTable method to work the schema of DataTable should be identical. Yet even with the simple C# example below, which only adds a row to the DataTable without modifying any other parameters, FromADODataTable method is not able to convert the resulting DataTable to a SAPTable.

Please advise what the recommended method of getting data from DataTable into a SAPTable is.

Thank you in advance.

Source code:

// This contains all the needed table structure and no rows

BAPILOCRANGETable tblValue = new BAPILOCRANGETable();

DataTable tblTmp = tblValue.ToADODataTable();

DataRow rw = tblTmp.NewRow();

rw["Sign"] = "I";

rw["Option"] = "CP";

rw["Low"] = "*";

tblTmp.Rows.Add( rw );

// Crashes on the next line, error is:

// "Object type cannot be converted to target type"

tblValue.FromADODataTable( tblTmp );

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Jun 23, 2005 at 01:44 PM

    Hi, I think If you change you code like this, it will go well

    BAPILOCRANGETable tblValue = new BAPILOCRANGETable();

    DataTable tblTmp = tblValue.ToADODataTable();

    DataRow rw = tblTmp.NewRow();

    rw["Sign"] = "I";

    rw["Option"] = "CP";

    rw["Low"] = "*";

    rw["High"] = ""; // pay attention to this line!

    tblTmp.Rows.Add( rw );

    tblValue.FromADODataTable( tblTmp );

    I find before call the FromADODataTable, all of the fields should be no-null, if not, it will throw out the error you mentioned.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Reiner Hille-Doering

      Hi All,

      I'm in a situation where i'm adding new rows to my SAPTable using the SAPstructure, then displaying in a datagrid what i've added to the SAPTable. It all appears to work but I only end up with 1 record from 3 in my datagrid. Anyone got any ideas?

      Code shown below:

      string commandtext = "select * from SAPUKLIB.BAPIE1MARA";

      iDB2Command cmd = new iDB2Command(commandtext);

      cmd.Connection = conn;

      iDB2DataAdapter adapter = new iDB2DataAdapter(cmd);

      DataTable client_table = new DataTable();

      adapter.Fill(client_table);

      foreach (DataRow da in client_table.Rows)

      {

      clientdatastruct.Allowed_Wt = Convert.ToDecimal(da["BMR042"]);

      clientdata.CreateNewRow();

      clientdata.Add(clientdatastruct);

      }

      dataGrid1.DataSource = clientdata;

      dataGrid1.Refresh();

      Message was edited by:

      Jim Kiriazis

  • author's profile photo
    Former Member
    Posted on Aug 17, 2004 at 04:45 PM

    Hi,

    please check that the field-types in "tblValue" are the same as in "rw". Use explicit type-casting for DataRow values.

    Or use datasets and specify the fields in the dataset-shema exact like the field-types used in your SAP-structure.

    Something like

    sqlDataAdapter.Fill(dataset.viewName);

    sapTabeleStructure.FromADODataTable(dataset.viewName);

    Regards

    Gerhard

    Message was edited by: Gerhard Rausch

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 17, 2004 at 09:29 PM

    Hi, there,

    Have you also tried to add a SAPStructure instance directly to your SAPTable?

    It may look like:

    BAPILOCRANGETable tblValue = new BAPILOCRANGETable();

    BAPILOCRANGE tmpStructure = new BAPILOCRANGE();

    tmpStructure.Sign = "I";

    tmpStructure.Option = "CP";

    tmpStructure.Low = "*";

    tblValue.Add(tmpStructure);

    It may not be a elegant solution, but I think it works 😉

    Hope it helps...

    Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      > Have you also tried to add a SAPStructure instance

      > directly to your SAPTable?

      This helped, thank you very much!

      Yet does this mean that FromADODataTable method officially does not work? Very strange to hear that.

      Regards,

      Anton Maslo

      Message was edited by: Anton Maslo

  • author's profile photo
    Former Member
    Posted on Aug 30, 2004 at 10:00 PM

    I have been able to get the ToADODataTable and fromADODataTable working, and can say I have experienced no issues.

    Hear is some vb code...

    dim exptable as datatable

    dim er as datarow

    exptable = ZplanexpenseTable1.ToADODataTable

    I then manipulate it like any other ADO table

    er = exptable.NewRow

    er(0) = reader3.getvalue(1)

    .....

    exptable.Rows.Add(er)

    then when I am done building the table

    ZplanexpenseTable1.FromADODataTable(exptable)

    I have had no issues and I have had this code in a production environment for a long time.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Todd, thanks for your reply. Your code looks identical to ours (posted by Robin), yet yours works and ours doesn't. This means that we are probably facing some configuration issue which we will need to research.

      Yet thank you for assuring me that it SHOULD work. This is good to know.

      Regards,

      Anton Maslo

  • author's profile photo
    Former Member
    Posted on Aug 31, 2004 at 02:22 PM

    Do you create the tables using the wizard or do you just declare them in the code? It may just be in my head but it seems like it is easier to manipulate the table if I drop it in using the wizard.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I looked at the code the wizard puts in the form and it may give you something to look at. Today is not a really good day for me to put together any sample code. So I hope this helps. I'll see if I can't generate a table from code later today or early tomorrow, If I have time I'll post the results

      It creates a new instance of the table in the web form generated section of the code.

      Me.ZActualsTableSAD = New SAPProxyAdmin.ZPLANNINGDATATable()

      It then initializes the tables

      CType(Me.ZActualsTableSAD, System.ComponentModel.ISupportInitialize).BeginInit()

      CType(Me.BdcmsgcollTable1, System.ComponentModel.ISupportInitialize).BeginInit()

      CType(Me.T100Table2, System.ComponentModel.ISupportInitialize).BeginInit()

      It sets properties on the data table

      Me.ZActualsTableSAD.AllowEdit = True

      Me.ZActualsTableSAD.AllowNew = True

      Me.ZActualsTableSAD.AllowRemove = True

      Me.ZActualsTableSAD.SupportsChangeNotification = True

      It then ends the initialization

      CType(Me.ZActualsTableSAD, System.ComponentModel.ISupportInitialize).EndInit()

      CType(Me.BdcmsgcollTable1, System.ComponentModel.ISupportInitialize).EndInit()

      CType(Me.T100Table2, System.ComponentModel.ISupportInitialize).EndInit()

      I'll dynamically create a table and I'll get back with you on the results.