2
Answers

oCompnay = null

Photo of Ramco Ramco

Ramco Ramco

Mar 15
237
1

Ho

  In oComany it shows null value. It gives error :Object Reference not set to an instance of the Object.

When i write code of  PendingInvoice in Constructor it works fine

public partial class Form1 : Form
{
    public static SAPbouiCOM.Application oApplication = null;
    public static SAPbobsCOM.Company oCompany = null;
    public static SAPbouiCOM.Form oForm = null;

    public Form1()
    {
        //InitializeComponent();

        SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
        oCompany.Server = "[email protected]:30015";
        oCompany.DbServerType = BoDataServerTypes.dst_HANADB;
        oCompany.CompanyDB = "TestE";
        oCompany.UserName = "manager";
        oCompany.Password = "123";
        oCompany.language = BoSuppLangs.ln_English;
        oCompany.UseTrusted = true;

        int connectionResult = oCompany.Connect();
        if (connectionResult != 0)
        {
            throw new Exception("Error connecting to SAP Business One: " + oCompany.GetLastErrorDescription());
        }

        PendingInvoice();
}

private void PendingInvoice()
{
    string _StrSQL = "SELECT 'Invoice',T0.\"TransId\", T0.\"DocNum\", T0.\"DocDate\", T0.\"BPLName\", T0.\"CardCode\" " +
    ", T0.\"CardName\", T0.\"DocTotal\", T4.\"U_UTL_IRN\" " +
    "FROM \"Test\".OINV T0 " +
    "INNER JOIN CRD1 T3 ON T0.\"CardCode\" = T3.\"CardCode\"  " +
    "INNER JOIN INV12 T5 ON T5.\"DocEntry\" = T0.\"DocEntry\" " +
    "LEFT JOIN \"Test\".\"@AUTL_MDEXTH\"  T4 ON T0.\"DocEntry\" = T4.\"U_UTL_BaseEntry\" " +
    "where T0.\"CardCode\" = T3.\"CardCode\"  and T0.\"PayToCode\" = T3.\"Address\"  and T3.\"AdresType\" = 'B' and T3.\"GSTRegnNo\" <> '' " +
    "and T0.\"DocEntry\" NOT IN(Select A4.\"U_UTL_BaseEntry\" from \"test\".\"@AUTL_MDEXTH\" A4 where A4.\"U_UTL_IST\" <> 'F' ) " +
    "and T5.\"LocGSTN\" <> T5.\"BpGSTN\" and T0.\"BPLId\" = '28'"  + "";

    SAPbobsCOM.Recordset oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
    oRecordSet.DoQuery(_StrSQL);
}


}

Thanks

Answers (2)