cancel
Showing results for 
Search instead for 
Did you mean: 

SAP .NET Connector, Method FromADOTable() crashed

Former Member
0 Kudos

Hi anyone,

I'm using SAP .NET Connector version 2.0 to access user tables and modify profile or group memberships with generated "USER" proxy object (i.e. RFC call to BAPI "USER") .

After calling the "USER.GetDetail" method I got a table with all activity group memberships of referenced user (type "SAP.Connector.SAPTable").

Then I try to convert this table into ADO datatable object using method "ToADODataTable". This works fine.

I add a new row to this table and have to save it into SAP.

myADOTable = myTable.ToADODataTable ();

currRow = myADOTable.NewRow ();

currRow["Agr_name"] = newMemberValue;

myADOTable.Rows.Add (currRow);

myTable.FromADODataTable (myADOTable);

If I try to convert ADO datatable back to corresponding SAPTable I get an exception like this "Der Objekttyp kann nicht zum Zieltyp konvertiert werden.".

Where is the mistake?

Thanks in advance for any ideas,

Tino

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

ADO.NET tables are not typesafe, in contrast to SAPTables.

It can easily happen that you add something to ADO.NET table that cannot be casted to the type in the SAPTable.

Please check the new row with a debugger and check that all columns contain values with the type of the SAPStructure.

Another typical problem are colums that contain DBNull. This can never be casted to any target type (e.g. string).

BTW: Generally I would recommend to work directly with SAPTables instead of converting to and from DataTables.

Former Member
0 Kudos

Hi Reiner,

thank you for posting this helpful information. If I initialze all fields of new row my code works fine.

One question about your notice at the end of your posting.

How do I add a new membership to a SAP.Connector.SAPTable (e.g. BAPIAGRTable) without using the path ToADO()..Add()..FromADO() ? SAPTable doesn't have an Add() method.

Thanks in advance,

Tino

reiner_hille-doering
Active Contributor
0 Kudos

Sure it does have an Add method. It only doesn't have an NewRow, because you can simply create the underlying structure, e.g.

BAPIAGRTTable tab = new BAPIAGRTTable();
//...
BAPIAGRT newRecord = new BAPIAGRT();
// Initialize the new record
newRecord.Field1 = "Value1";

tab.Add(newRecord);

Former Member
0 Kudos

OK, if I use the method named "AddNew" this works really.

Thanks a lot for your useful informations.

Bye

Tino

reiner_hille-doering
Active Contributor
0 Kudos

One more remark (maybe usefull for somebody): Perhaps you haven't found the Add (and Delete, indexer and so on) method of the SAPTables, because they don't appear in the Documentation - but the do appear in Intellisense.

Why?

Because they are not implemented in the base class

SAPTAble

, but in each table class as part of your proxy. This is because we want these methods to be strongly typed.

AddNew is different, because it belongs to IBindingList, so it appears in the docu.

All in all SAPTables should have all features you need, including sorting, filtering, databinding, indexed access and so forth.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

probably you have left some new fields empty. Specially numeric fields (e.g. decimal) have to be filled.

Gerhard Rausch

P.S.: Reiner was a little bit faster

Message was edited by: Gerhard Rausch