Click here to Skip to main content
15,896,557 members
Articles / Web Development / ASP.NET

Transferring Data from SAP to .NET using ERPConnect

Rate me:
Please Sign up or sign in to vote.
4.76/5 (21 votes)
23 May 2007CPOL10 min read 179.8K   8.9K   83  
Description of an interface programming tool for SAP and .NET integration.
using System;
using System.Data;
using System.Text;
using ERPConnect;
using ERPConnect.Utils;
using System.Windows.Forms;

namespace CustomerSearch
{
    class SAPConn
    {
        private  string _userName;
        private  string _password;
        private  string _client;
        private R3Connection _con;

        public SAPConn(string userName, string password, string client)
        {
            _userName = userName;
            _password = password;
            _client = client;
        }

        private void openConnection()
        {
            ERPConnect.LIC.SetLic("Licence Code");

            R3Connection connection = new R3Connection("Server Name",
                                                11,
                                                _userName,
                                                _password,
                                                "DE",
                                                _client);
            try
            {
                connection.Open();
            }
            catch (ERPException e)
            {

                /*put your errHandler here
                 * in this error case the program was not able to connect
                 * to the SAP system so you have to check your connection string*/
                MessageBox.Show(e.Message);
            }

            _con = connection;
        }

        private void closeConnection()
        {
            _con.Close();
        }

        public DataTable WhereLikeSearch(string sapTable, string nameCriteria)
        {
            openConnection();

            //creating a ReadTable object
            ReadTable table = new ReadTable(_con);

            //setting the table name that we want to read from
            table.TableName = sapTable;
        
            //adding the fields we want to display in our DataTable
            table.AddField("NAME1");
            table.AddField("STRAS");
            table.AddField("ORT01");
            table.AddField("PSTLZ");
            table.AddField("TELF1");
            table.AddField("TELFX");
                 
            //this is the 
            table.WhereClause = string.Format("NAME1 LIKE '%{0}%'", nameCriteria);    

            //this is an optional property
            table.RowCount = 100;

            //executing the query
            try
            {
                table.Run();
            }
            catch(ERPException e)
            {
                MessageBox.Show(e.Message);
            }

            DataTable dt = table.Result;

            closeConnection();

            return dt;

        }
        //table.WhereClause = string.Format("NAME1 = '{0}'", nameCriteria);

        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer FMP software & process engineering GmhH
Germany Germany
Im working as freelance consultant and software engineer in southern germany. If you have any questions about this article please contact me.

Comments and Discussions