|
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.
Im working as freelance consultant and software engineer in southern germany. If you have any questions about this article please contact me.