添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
文雅的椅子  ·  Solved: Alteryx ...·  1 周前    · 
拉风的黄瓜  ·  Results - OpenURL ...·  1 周前    · 
胡子拉碴的豆腐  ·  Mongoose URI is ...·  1 周前    · 
彷徨的青蛙  ·  Results - OpenURL ...·  5 天前    · 
傻傻的柚子  ·  python ...·  2 月前    · 

In the following turtorial i will show you how to connect to di-api using c#.

I have added a example c# project in the references so you can copy it.

Step 1: Create new project

create a new project console or forms i will base my turtorial on a forms method.

Step 2: Add app.config

create a new app.config.xml file and add this contents.

adjust the required parameters to your setup

Step 3: create a new class file

this class file wil be the connection to the server add a new class file and call this name : ServerConnections.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DIAPI_Froms
class ServerConnection
private SAPbobsCOM.Company company = new SAPbobsCOM.Company();
private int connectionResult;
private int errorCode = 0;
private string errorMessage = “”;

    public int Connect()
        company.Server = ConfigurationManager.AppSettings["server"].ToString();
        company.CompanyDB = ConfigurationManager.AppSettings["companydb"].ToString();
        company.DbUserName = ConfigurationManager.AppSettings["dbuser"].ToString();
        company.DbPassword = ConfigurationManager.AppSettings["dbpassword"].ToString();
        company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
        company.UserName = ConfigurationManager.AppSettings["user"].ToString();
        company.Password = ConfigurationManager.AppSettings["password"].ToString();
        company.language = SAPbobsCOM.BoSuppLangs.ln_Dutch;
        company.UseTrusted = false;
        company.LicenseServer = ConfigurationManager.AppSettings["licenseServer"].ToString();
        connectionResult = company.Connect();
        if (connectionResult != 0)
            company.GetLastError(out errorCode, out errorMessage);
        return connectionResult;
    public SAPbobsCOM.Company GetCompany()
        return this.company;
    public int GetErrorCode()
        return this.errorCode;
    public String GetErrorMessage()
        return this.errorMessage;

Step 4: add references

add system.configuration to the references and SAPBOBSCOM this you can locate at :“C:\Program Files (x86)\SAP\SAP Business One DI API\DI API 90\SAPbobsCOM90.dll”

Step 5: edit form

add 2 fields to your main form ItemCode and ItemName

and give them a good name like:
txt_itemcode
txt_itemname

add a button to the main screen and double click on it. now we will add code in the next step.

to test the output you need to query your sql server eg:

select ItemCode,ItemName FROM OITM Where ItemCode = ‘YOUR_ITEM_HERE’

if the data is changed you have succefully connected to the api.

if you want more info about software dev in sap you need to download SAP SDK this will install the documentation in the following location:

C:\Program Files (x86)\SAP\SAP Business One SDK\Help