简体   繁体   中英

Insert Data SAP B1 with C#

I'm trying to input purchase order data with the DI API in C #. after I run the script, the connection is successful and the input data is successful but when I check SAP the input data is not there. this is the script I used:

try {

                    SAPbobsCOM.Documents PO = null;
                    PO = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
                    PO.CardCode = "VT0970";
                    PO.CardName = "FELICOM";
                    PO.Series = int.Parse("16N");
                    PO.DocNum = 211000002;
                    PO.DocDate = DateTime.Parse("15.10.19");
                    PO.DocDueDate = DateTime.Parse("18.10.19");
                    PO.TaxDate = DateTime.Parse("15.10.19");

                    PO.Lines.ItemCode = "TH-NONSTOK";
                    PO.Lines.ItemDescription = "Mouse Rexus G-6";
                    PO.Lines.Quantity = 2;
                    PO.Lines.Price = 150000;
                    PO.DiscountPercent = 0;
                    PO.Lines.VatGroup = "IPPN0";
                    PO.Lines.AccountCode = "6020-1500";
                    PO.Lines.Add();
                    int res = PO.Add();
                    if (res == 0)
                    {
                        MessageBox.Show("Add Purchase Order successfull");

                    }
                    else
                    {
                        MessageBox.Show(ocompany.GetLastErrorDescription()); //@scope_identity
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

Is there something wrong with my script? Please help.

after "Add Purchase Order successfull" should be commit work

if (ocompan.InTransaction)
    ocompan.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
else
    throw new Exception("ERROR: Transaction closed before EndTransaction!!!");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM