How to use a DLL library for Excel in C#

  • Thread starter Thread starter Igor-M
  • Start date Start date
I

Igor-M

Guest
Hi,

I've been mostly working in VBA but recently decided to switch to VSTO (C#). I have a solution in Excel VBA for the Exact Globe Next general ledger syste that uses a few DLLs provided by Exact to connect to the database.

I wanted to build a reporting excel add-in in C# but I do not know how to add and use the libraries in my code.

A sample library called CSSDKConnect.dll can be used here:

https://reep.io/d/null0xlk


I was trying to register the DLL using regsvr32, as per suggestions in my old post here Using Exact Globe DLLs in C# code, but I failed to do so.


I am relatively new to C#, hence I'd really appreciate clear answers.


Below is a sample code in VBA showing the use of the libraries


Sub MainApp()

Dim cEDLQuery As EdlQuery

Dim sQuery As String

GlobalVariableDeclarations

ConnectToExact iError, "db_name_123", "010"

sQuery = "SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES"

Set cEDLQuery = gEDLConnection.OpenQuery(sQuery, edlClientSnapshot, edlReadOnly, edlOptDontParse)

cEDLQuery.FetchFirst

While Not cEDLQuery.EOF

' do something here

cEDLQuery.FetchNext

Wend

DisconnectFromExact

End Sub



Sub GlobalVariableDeclarations()

Public gSDKConnect As CSSDKConnect.SDKConnect

Public gSDKConnection As CSSDKConnect.SDKConnection

Public gEDLConnection As EDL.EdlConnection

Public cConnError As CSSDKConnect.SDKConnectionErrors ' 1000 – no errors

End Sub



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Comments: This routine is responsible for creating a connection to

' Exact Globe databases.

'

' Arguments: None

'

' Returns: None



Public Sub ConnectToExact(ByRef Error As Integer, sServerName As String, sDataBaseName As String)

Dim sProcName As String

Dim sErrorMessage As String

Error = 0

On Error GoTo ErrHandler

Dim cConnError As CSSDKConnect.SDKConnectionErrors

Set gSDKConnect = New CSSDKConnect.SDKConnect

cConnError = gSDKConnect.ConnectDirect(sServerName, sDataBaseName, gSDKConnection)

If cConnError <> ConnNoError Then

Call MsgBox("Error connecting to database" & vbNewLine & _

"SDKConnectionError: " & cConnError, vbCritical)

GoTo ErrHandler

End If

Set gEDLConnection = gSDKConnection.Environment.Connection

Exit Sub

ErrHandler:

Error = 1



End Sub



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Comments: This routine closes active connection to

' Exact Globe database.

'

' Arguments: None

'

' Returns: None

Public Sub DisconnectFromExact()



On Error GoTo ErrHandler

If Not gSDKConnection Is Nothing Then

Call gSDKConnect.Disconnect(gSDKConnection)

Set gSDKConnect = Nothing

End If

Exit Sub

ErrHandler:

MsgBox "Error disconnecting: '" & Err.Description & "' ", vbCritical + vbOKOnly, gsAPP_NAME

End Sub



Kind regards,

Igor


-- Igor M.

Continue reading...
 
Back
Top