Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFTableConnections Class

  • Last UpdatedNov 18, 2025
  • 10 minute read
AFTableConnections Class
The AFTableConnection collection allows you to define and/or access connection information for database tables.

Inheritance Hierarchy

SystemObject
  OSIsoft.AFAFCollection
    OSIsoft.AFAFCollectionAFTableConnection
      OSIsoft.AFAFNamedCollectionAFTableConnection
        OSIsoft.AF.AssetAFTableConnections

Namespace:  OSIsoft.AF.Asset
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public sealed class AFTableConnections : AFNamedCollection<AFTableConnection>
Public NotInheritable Class AFTableConnections
	Inherits AFNamedCollection(Of AFTableConnection)

Dim instance As AFTableConnections
public ref class AFTableConnections sealed : public AFNamedCollection<AFTableConnection^>
[<SealedAttribute>]
type AFTableConnections =  
    class
        inherit AFNamedCollection<AFTableConnection>
    end

The AFTableConnections type exposes the following members.

Properties

  NameDescription
Public property
Count
Gets the number of items actually contained in the collection.
(Inherited from AFCollectionT.)
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
Public property
Identity
This read-only property contains identity of the object.
(Inherited from AFCollection.)
Public property
IsDeleted
This read-only property indicates whether the owner of the collection has been deleted.
(Inherited from AFCollection.)
Public property
ItemGuid
Returns the item in the collection associated with the passed in ID.
(Inherited from AFCollectionT.)
Public property
ItemInt32
Returns the item located at the passed in index.
(Inherited from AFCollectionT.)
Public property
ItemString
Returns the specified object from the collection by name.
(Inherited from AFNamedCollectionT.)
Public property
ItemIdentity
This read-only property specifies the identity of the objects within the collection.
(Inherited from AFCollection.)
Public property
PISystem
This read-only property allows access to the PISystem associated with this collection.
(Inherited from AFCollection.)

Methods

  NameDescription
Public method
Add(T)
Adds an object to the end of the collection.
(Inherited from AFCollectionT.)
Public method
Add(String)
The Add method creates a new object and adds it to the collection.
Public method
Clear
Removes all items from the collection.
(Inherited from AFCollectionT.)
Public method
Contains(Guid)
This method determines whether the collection contains a specific item referenced by id.
(Inherited from AFCollectionT.)
Public method
Contains(T)
This method determines whether the collection contains a specific item.
(Inherited from AFCollectionT.)
Public method
Contains(String)
This method determines whether the collection contains a specific item referenced by name.
(Inherited from AFNamedCollectionT.)
Public method
CopyTo
Copies the entire collection to a compatible one-dimensional Array, starting at the specified index of the target array.
(Inherited from AFCollectionT.)
Public method
Equals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public method
GetEnumerator
Returns an enumerator that iterates through the collection.
(Inherited from AFCollectionT.)
Public method
GetHashCode
Gets the hash code for this instance of the object which is suitable for use in hashing algorithms and data structures like a hash table.
(Inherited from AFCollection.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
IndexOf
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection.
(Inherited from AFCollectionT.)
Public method
Refresh
Refresh the collection to make sure it's list of items is up-to-date.
Public method
Remove(Guid)
Removes the item with the specified id from the collection.
(Inherited from AFCollectionT.)
Public method
Remove(T)
Removes the first occurrence of a specific object from the collection.
(Inherited from AFCollectionT.)
Public method
Remove(String)
The Remove method removes the item from the collection by name.
(Inherited from AFNamedCollectionT.)
Public method
RemoveAt
Removes the item at the specified index of the collection.
(Inherited from AFCollectionT.)
Public method
Sort
Sorts the items in the entire collection using the default comparer.
(Inherited from AFCollectionT.)
Public method
Sort(IComparerT)
Sorts the items in the entire collection using the specified comparer.
(Inherited from AFCollectionT.)
Public method
Sort(Int32, Int32, IComparerT)
Sorts the items in a range of items in the collection using the specified comparer.
(Inherited from AFCollectionT.)
Public method
ToString
Returns a String that represents the current object.
(Inherited from AFCollection.)

Remarks

A table connection is used by an AFTable to configure the information required to establish a connection to a linked table.

Examples

// This example demonstrates how to link an existing external table to an AFTable with an
// AFTableConnection configured to use an ADODB.Recordset and three .NET data adapters (ODBC,
// OLEDB, and SQL). The link to the SQL Server table is configured to use parameters.
// Note: This sample uses a sample MS Access 2010 database that can be downloaded from Microsoft at:
// http://office.microsoft.com/en-us/templates/northwind-sales-web-database-TC101114818.aspx

// This example will work with 64 bit Microsoft Office 2010 and SQL Server 2012 - some 
// modifications to connection strings will be necessary to work with other versions
// of Microsoft Office and Microsoft SQL Server or on 32 bit systems.

// Get the Database 
PISystems myPISystems = new PISystems();
AFDatabase myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase;

// Create the parameters used in the table query
Dictionary<string, object> myParameters = new Dictionary<string, object>();
myParameters.Add("@City", "London");

// Create the password used when connecting to the external table
System.Security.SecureString password = new System.Security.SecureString();
foreach (char c in SqlPassword)
{
    password.AppendChar(c);
}

password.MakeReadOnly();

// ****************************************************
// Create a Table Connection using an OLEDB data adapter
// ****************************************************
AFTableConnection myConnection = myDB.TableConnections.Add("Employees OLEDB");
myConnection.Description = "This is my employee table connection using OLEDB data adapter.";
myConnection.ImpersonateUser = true;
myConnection.ExternalConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Northwind.accdb";
myConnection.ExternalType = typeof(OleDbDataAdapter).FullName;
myConnection.CheckIn();

// Create a Table and Link to the External Table using the OLEDB data adapter Table Connection
AFTable myTable = myDB.Tables.Add("Employees OLEDB");
myTable.Description = "This is my employee table using OLEDB data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM Employees", null);
myTable.CheckIn();

// ***************************************************
// Create a Table Connection from Excel using an ODBC data adapter
// ***************************************************
myConnection = myDB.TableConnections.Add("Employees ODBC");
myConnection.Description = "This is my employee table connection using ODBC data adapter.";
myConnection.ImpersonateUser = true;
myConnection.ExternalConnection = @"DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=\Employees.xlsx";
myConnection.ExternalType = typeof(OdbcDataAdapter).FullName;

// Create a Table and Link to the External Table using the ODBC data adapter Table Connection
myTable = myDB.Tables.Add("Employees ODBC");
myTable.Description = "This is my employee table from Excel using ODBC data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM A1:F10", null);
myTable.CheckIn();

// *************************************************
// Create a Table Connection using a SQL data adapter
// *************************************************
myConnection = myDB.TableConnections.Add("Employees SQL");
myConnection.Description = "This is my employee table connection using SQL data adapter.";
myConnection.ExternalConnection = $"Server={SqlServerMachineName};Database=Northwind;User Id={SqlUserId};Password=<PASSWORD>;Trusted_Connection=False;";
myConnection.ExternalType = typeof(SqlDataAdapter).FullName;
myConnection.SecurePassword = password;

// Create a Table and Link to the External Table using the SQL data adapter Table Connection
myTable = myDB.Tables.Add("Employees SQL");
myTable.Description = "This is my employee table using SQL data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM Employees WHERE [City] = @City", myParameters);
myTable.CheckIn();

// Display the DataTable using Parameters
myParameters = new Dictionary<string, object>();
myParameters.Add("@City", "Seattle");
DataTable table = myTable.GetTableWithParameters(myParameters);
StringBuilder line = new StringBuilder();
foreach (DataColumn col in table.Columns)
{
    line.AppendFormat("{0}, ", col.ColumnName);
}
Console.WriteLine(line.ToString());
line.Clear();
foreach (DataRow row in table.Rows)
{
    foreach (DataColumn col in table.Columns)
    {
        line.AppendFormat("{0}, ", row[col.ColumnName]);
    }
    Console.WriteLine(line.ToString());
    line.Clear();
}

// The Table can be Refreshed Manually using AFTable.Refresh
myTable.Refresh();
' This example demonstrates how to link an existing external table to an AFTable using an ADODB.Recordset
' AFTableConnection configured to use an ADODB.Recordset and three .NET data adapters (ODBC,
' OLEDB, and SQL). The link to the SQL Server table is configured to use parameters.
' Note: This sample uses a sample MS Access 2010 database that can be downloaded from Microsoft at:
' http://office.microsoft.com/en-us/templates/northwind-sales-web-database-TC101114818.aspx

' This example will work with 64 bit Microsoft Office 2010 and SQL Server 2012 - some 
' modifications to connection strings will be necessary to work with other versions
' of Microsoft Office and Microsoft SQL Server or on 32 bit systems.

' Get the Database 
Dim myPISystems As New PISystems
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases.DefaultDatabase

' Create the parameters used in the table query
Dim myParameters As New Dictionary(Of String, Object)()
myParameters.Add("@City", "London")

' Create the password used when connecting to the external table
Dim password As System.Security.SecureString = New System.Security.SecureString
For Each c As Char In SqlPassword
    password.AppendChar(c)
Next

password.MakeReadOnly()

' ****************************************************
' Create a Table Connection using an OLEDB data adapter
' ****************************************************
Dim myConnection As AFTableConnection = myDB.TableConnections.Add("Employees OLEDB")
myConnection.Description = "This is my employee table connection using OLEDB data adapter."
myConnection.ImpersonateUser = True
myConnection.ExternalConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Northwind.accdb"
myConnection.ExternalType = GetType(OleDbDataAdapter).FullName
myConnection.CheckIn()

' Create a Table and Link to the External Table using the OLEDB data adapter Table Connection
Dim myTable As AFTable = myDB.Tables.Add("Employees OLEDB")
myTable.Description = "This is my employee table using OLEDB data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM Employees", Nothing)
myTable.CheckIn()

' ***************************************************
' Create a Table Connection from Excel using an ODBC data adapter
' ***************************************************
myConnection = myDB.TableConnections.Add("Employees ODBC")
myConnection.Description = "This is my employee table connection using ODBC data adapter."
myConnection.ImpersonateUser = True
myConnection.ExternalConnection = "DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=\Employees.xlsx"
myConnection.ExternalType = GetType(OdbcDataAdapter).FullName

' Create a Table and Link to the External Table using the ODBC data adapter Table Connection
myTable = myDB.Tables.Add("Employees ODBC")
myTable.Description = "This is my employee table from Excel using ODBC data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM A1:F10", Nothing)
myTable.CheckIn()

' *************************************************
' Create a Table Connection using a SQL data adapter
' *************************************************
myConnection = myDB.TableConnections.Add("Employees SQL")
myConnection.Description = "This is my employee table connection using SQL data adapter."
myConnection.ExternalConnection = $"Server={SqlServerMachineName};Database=Northwind;User Id={SqlUserId};Password=<PASSWORD>;Trusted_Connection=False;"
myConnection.ExternalType = GetType(SqlDataAdapter).FullName
myConnection.SecurePassword = password

' Create a Table and Link to the External Table using the SQL data adapter Table Connection
myTable = myDB.Tables.Add("Employees SQL")
myTable.Description = "This is my employee table using SQL data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM Employees WHERE [City] = @City", myParameters)
myTable.CheckIn()

' Display the DataTable using Parameters
myParameters = New Dictionary(Of String, Object)()
myParameters.Add("@City", "Seattle")
Dim table As DataTable = myTable.GetTableWithParameters(myParameters)
Dim line As New StringBuilder()
For Each col As DataColumn In table.Columns
    line.AppendFormat("{0}, ", col.ColumnName)
Next
Console.WriteLine(line.ToString())
line.Clear()
For Each row As DataRow In table.Rows
    For Each col As DataColumn In table.Columns
        line.AppendFormat("{0}, ", row(col.ColumnName))
    Next
    Console.WriteLine(line.ToString())
    line.Clear()
Next

' The Table can be Refreshed Manually using AFTable.Refresh
myTable.Refresh()

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6

See Also

TitleResults for “How to create a CRG?”Also Available in