cancel
Showing results for 
Search instead for 
Did you mean: 

Help , How to get data from database using recordset with UI API

Former Member
0 Kudos

I want to get a data from database

when I want to create recordset i notice that UI API didn't has record set

so I created recordset using DI API (SAPbobscom.recordset and SAPbobscom.company)

======================================================

Dim oCompanyUI As SAPbouiCOM.Company <<UI API

Dim oRecSet As New SAPbobsCOM.Recordset << DI API

Dim oCompanyDI As New SAPbobsCOM.Company << DI API

'=====================================================

oCompanyDI.Connect

Set oRecSet = oCompanyDI.GetBusinessObject(BoRecordset)

oRecSet.DoQuery ("SELECT T0.CardCode, T0.CardName FROM OCRD T0")

SBO_Application.MessageBox oRecSet.Fields.Item(1).Value

======================================================

but I got an error it said "you are not connected to company"

I'm really don't have an idea about how to get a data from using UI API (exp I want to get a date or costumer code)

can someone help me please, I really need it

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

olivier_huet3
Participant
0 Kudos

Try to add this code instead of the "oCompanyDI.Connect" line :


            Dim sCookie as string
            Dim sConnectionContext as string
            Dim Ret as integer

            sCookie = oCompanyDI.GetContextCookie
            sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)
            If oCompanyDI.Connected Then oCompanyDI.Disconnect() 

            Ret = oCompanyDI.SetSboLoginContext(sConnectionContext)
            If Ret <> 0 Then
               SBO_Application.MessageBox("Cannot set login context. Connection failed !")
            Else
                Ret = oCompanyDI.Connect
                If Ret<>0 Then SBO_Application.MessageBox("Connection failed !")
            End If

Former Member
0 Kudos

Hi

Keremans thanks for the answer

and Olivier yes it works

Thank You Very Much and You are my Hero

Answers (2)

Answers (2)

Former Member
0 Kudos

you need a single sign on

Dim oDICompany As SAPbobsCOM.Company

Dim sCookie As String

Dim sConnStr As String

Dim ret As Integer

oDICompany = New SAPbobsCOM.Company

sCookie = oDICompany.GetContextCookie

sConnStr = SBO_Application.Company.GetConnectionContext(sCookie)

If oDICompany.Connected Then

oDICompany.Disconnect()

End If

ret = oDICompany.SetSboLoginContext(sConnStr)

If Not ret = 0 Then

SBO_Application.MessageBox("set Login Context failed!")

Exit Sub

End If

ret = oDICompany.Connect()

If Not ret = 0 Then

SBO_Application.MessageBox("Company Connect failed!")

End If

AdKerremans
Active Contributor
0 Kudos

Hi Acumen,

I assume you want to do this from an addon, so you als must connect to SBO using the DI.

If you look int the SDK help and/or samples UIDIBasicApp in C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI DI\VB.NET\UIDIBasicApp

you will find the solution for your problem.

Regards

Ad