AFTableConnections Class
- Last UpdatedJan 12, 2026
- 8 minute read
- PI System
- AF SDK 3.2.0
- Developer
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
OSIsoft.AFAFCollection
OSIsoft.AFAFCollectionAFTableConnection
OSIsoft.AFAFNamedCollectionAFTableConnection
OSIsoft.AF.AssetAFTableConnections
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
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
| Name | Description | |
|---|---|---|
| Count |
Gets the number of items actually contained in the collection.
(Inherited from AFCollectionT.) | |
| Database |
This read-only property returns the AFDatabase where this object is defined.
| |
| Identity |
This read-only property contains identity of the object.
(Inherited from AFCollection.) | |
| IsDeleted |
This read-only property indicates whether the owner of the collection has been deleted.
(Inherited from AFCollection.) | |
| ItemGuid | Returns the item in the collection associated with the passed in ID. (Inherited from AFCollectionT.) | |
| ItemInt32 | Returns the item located at the passed in index. (Inherited from AFCollectionT.) | |
| ItemString |
Returns the specified object from the collection by name.
(Inherited from AFNamedCollectionT.) | |
| ItemIdentity |
This read-only property specifies the identity of the objects within the collection.
(Inherited from AFCollection.) | |
| PISystem |
This read-only property allows access to the PISystem
associated with this collection.
(Inherited from AFCollection.) |
Methods
| Name | Description | |
|---|---|---|
| Add(T) |
Adds an object to the end of the collection.
(Inherited from AFCollectionT.) | |
| Add(String) |
The Add method creates a new object and adds it to the collection.
| |
| Clear |
Removes all items from the collection.
(Inherited from AFCollectionT.) | |
| Contains(Guid) |
This method determines whether the collection contains a specific item referenced by id.
(Inherited from AFCollectionT.) | |
| Contains(T) |
This method determines whether the collection contains a specific item.
(Inherited from AFCollectionT.) | |
| Contains(String) |
This method determines whether the collection contains a specific item referenced by name.
(Inherited from AFNamedCollectionT.) | |
| CopyTo |
Copies the entire collection to a compatible one-dimensional Array,
starting at the specified index of the target array.
(Inherited from AFCollectionT.) | |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator that iterates through the collection.
(Inherited from AFCollectionT.) | |
| 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.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| IndexOf |
Searches for the specified object and returns the zero-based index of the first
occurrence within the entire collection.
(Inherited from AFCollectionT.) | |
| Refresh |
Refresh the collection to make sure it's list of items is up-to-date.
| |
| Remove(Guid) |
Removes the item with the specified id from the collection.
(Inherited from AFCollectionT.) | |
| Remove(T) |
Removes the first occurrence of a specific object from the collection.
(Inherited from AFCollectionT.) | |
| Remove(String) |
The Remove method removes the item from the collection by name.
(Inherited from AFNamedCollectionT.) | |
| RemoveAt |
Removes the item at the specified index of the collection.
(Inherited from AFCollectionT.) | |
| Sort |
Sorts the items in the entire collection using the default comparer.
(Inherited from AFCollectionT.) | |
| Sort(IComparerT) |
Sorts the items in the entire collection using the specified comparer.
(Inherited from AFCollectionT.) | |
| Sort(Int32, Int32, IComparerT) |
Sorts the items in a range of items in the collection using the specified comparer.
(Inherited from AFCollectionT.) | |
| 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();