I have found many example on the Internet but many are old (VS 2003, SAP. Net Connector 2.0 where the current is 3.0).
I wonder how to use SAP. NET Connector.
What files should I install?
References which add to the project?
How to add the provider to create a connection in Server Explorer?
An example using vs2010 and SAP .NET Connector 3.0
Requirements:
Installation
Identify the correct version for your platform. You might have something along the following:
.. for a Windows 7 64-bit installation, we'll use
sapnco30dotnet40P_12-20007348.zip
.Expand the archive, and start the
.msi
installation file... follow the installation procedure, leaving all default options (next.. next.. next.. finish).
Referencing
Open Visual Studio and create a new project (or open your own).
In the
Solution Explorer
panel, usually to your right, right-click onReferences
and chooseAdd Reference
:.. then, select the
Browse
tab, navigate to the SAP Connector installation folder, and select bothsapnco.dll
andsapnco_utils.dll
:Now that you've correctly referenced the SAP .NET Connector in your Visual Studio project, you can write code for it.
Connecting
Start by creating a destination configuration class (replace the connection parameters with the ones you're given by your client):
.. then, connect to SAP and call a function. Suppose that you want to retrieve the list of companies, using the
BAPI_COMPANYCODE_GETLIST
SAP function:Making life easier
In the above example, the
GetTable
function returns a SAP table which you may like, or not. There's a handy extension that transforms that table in a familiar .NETDataTable
, as follows:Reference: http://antswift.wordpress.com/2011/12/22/irfctable-to-net-datatable-extention-method/
After adding the above extension, you can now transform the result into a
DataTable
:Notes
Additional Reading