This chapter will guide programmers on how to access TAFC/T24 data from various development environments.
Win32 environment
Visual Basic for Applications
Rad Studio (Delphi)
.NET Framework
Visual Basic .NET
Visual C# .NET
Visual Basic for Applications |
Before running the code, make sure the latest “Microsoft ActiveX Data Objects” library is added. That can be done from the menu Tools, <References> window. Pick the latest available version.
Now, the environment is ready for the code listed below:
Sub jBASE_ReadData() 'Defining variables Dim cnJB As ADODB.Connection Dim rsJB As ADODB.Recordset Dim db_name As String Set cnJB = New ADODB.Connection Set rsJB = New ADODB.Recordset 'Specify here the DSN db_name = "jbase4" 'Opening a connection to jBASE cnJB.Open "DSN=" + db_name + ";" rsJB.CursorLocation = adUseServer 'Running a query rsJB.Open "SELECT @ID FROM F_CATEGORY", cnJB, adOpenForwardOnly 'Reading the jBASE data from the recordset While Not rsJB.EOF Worksheets("Sheet1").Range("A1") = rsJB![@ID] rsJB.MoveNext Wend 'Closing objects rsJB.Close cnJB.Close Set rsJB = Nothing Set cnJB = Nothing End Sub |
RAD Studio (Delphi) |
procedure TForm1.Button1Click(Sender: TObject); jbq.SQL.Add('SELECT @ID FROM F_CATEGORY'); jbq.First; finally |
Visual Basic .NET |
The following article on Microsoft web site provides a step by step procedure on how to setup Visual Basic environment in order to work with native ODBC drivers in .NET Framework.
http://support.microsoft.com/kb/310985 (redirect)
https://support.microsoft.com/en-us/help/310985/how-to-use-the-odbc-net-managed-provider-in-visual-basic-net-and-conne
Prerequisites:
ODBC .NET Data Provider:
http://www.microsoft.com/downloads/details.aspx?familyid=6ccd8427-1017-4f33-a062-d165078e32b1 (not available)
https://download.cnet.com/ODBC-NET-Data-Provider/3000-2206_4-10731463.html (mirror)
Microsoft Data Access Components (MDAC) version 2.7 or later:
http://msdn.microsoft.com/en-us/data/aa937729.aspx
The following code must be added before the Public Class Form1 code:
Imports System.Data
Imports Microsoft.Data.ODBC
Dim cnJB As OdbcConnection Dim ocJB As OdbcCommand Dim drJB As OdbcDataReader Dim UsdCount As Integer Dim SelectStr As String = "SELECT CURRENCY FROM F_ACCOUNT" cnJB = New OdbcConnection("dsn=jbase40") cnJB.Open() ocJB = New OdbcCommand(SelectStr, cnJB) drJB = ocJB.ExecuteReader(CommandBehavior.CloseConnection) UsdCount = 0 While drJB.Read() If drJB.GetString(0) = "USD" Then UsdCount = UsdCount + 1 End If End While drJB.Close() cnJB.Close() Label1.Text = "USD accounts: " + Str(UsdCount) |
Visual C# .NET |
The following article on Microsoft web site provides a step by step procedure on how to setup C# environment in order to work with native ODBC drivers in .NET Framework.
http://support.microsoft.com/kb/310988 (redirect)
https://support.microsoft.com/en-us/help/310988/how-to-use-the-odbc-net-managed-provider-in-visual-c-net-and-connectio
Prerequisites:
ODBC .NET Data Provider:
http://www.microsoft.com/downloads/details.aspx?familyid=6ccd8427-1017-4f33-a062-d165078e32b1 (not available)
https://download.cnet.com/ODBC-NET-Data-Provider/3000-2206_4-10731463.html (mirror)
Microsoft Data Access Components (MDAC) version 2.7 or later:
http://msdn.microsoft.com/en-us/data/aa937729.aspx
The following code must be added after the other using statements:
using System.Data;
using Microsoft.Data.ODBC;
OdbcConnection cnJB; UsdCount = 0;
|