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

AF SDK Reference

AFTable.Table Property

  • Last UpdatedNov 18, 2025
  • 6 minute read
AFTable.Table Property
This property provides access to the cached data of a table.

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

Syntax

public DataTable Table { get; set; }
Public Property Table As DataTable
	Get
	Set

Dim instance As AFTable
Dim value As DataTable

value = instance.Table

instance.Table = value
public:
property DataTable^ Table {
	DataTable^ get ();
	void set (DataTable^ value);
}
member Table : DataTable with get, set

Property Value

Type: DataTable
Provides access to the cached data of a table.

Remarks

The Table property will return the complete table as an ADO.NET data table. If the table is not linked to an external table (see ExternalPersist), you can use the methods of the returned DataTable to add or update data. The CacheInterval property controls how often the table's cached data is automatically refreshed. The Refresh method can be used to force the cached data to be updated.

Caution note Caution
If the CacheInterval is set, accessing this property could cause the table's data to be updated. Therefore, you should use a local variable to limit the number of times this property is called if you do not want the data to change between access.

For tables stored within the PI Asset database (ExternalPersist is ), the entire table will be created and opened when you retrieve this property. The InitializeDataTable(AFTable, DataTable) method should be used to initialize the DataTable that will be used to set this property to handle special handling must be done for columns of type DateTime to set the column's DateTimeMode correctly.

For externally linked tables, this property will be read-only and the PI AF Server will attempt to open the external table when you retrieve this property. If the table query uses parameters, then this property will return the portion of the table using the default parameters. Use one of the LinkExternal Overload methods to modify the source of the table.

Important note Important
When modifying the table's schema (e.g. adding a column or changing a column name), you must first call CheckOut to check out the object and ensure you are modifying the latest copy of the table. When finished, call AFTable.Table.AcceptChanges to commit the schema changes. Changes to the table schema cannot be automatically detected like changes to other properties.

Examples

// This example demonstrates how to import a table using an ADO.NET DataTable to create an
// internal table. It also demonstrates setting and getting the extended properties of an AFTable.

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

// Create a small Table using an ADO.NET DataTable
DataTable dtMyTable = new DataTable();
dtMyTable.Locale = CultureInfo.CurrentCulture;
AFTable myTable = myDB.Tables.Add("myTable");
myTable.TimeZone = AFTimeZone.UtcTimeZone;
myTable.Description = "This is my table.";

dtMyTable.Columns.Add("TankName", typeof(System.String));
dtMyTable.Columns.Add("Height", typeof(System.Double));
dtMyTable.Columns.Add("Volume", typeof(System.Double));
dtMyTable.Columns.Add("Date", typeof(System.DateTime));
AFTable.InitializeDataTable(myTable, dtMyTable);

DataRow drMyRow0 = dtMyTable.NewRow();
drMyRow0["TankName"] = "TK101";
drMyRow0["Height"] = 0;
drMyRow0["Volume"] = 0;
drMyRow0["Date"] = DateTime.UtcNow;

DataRow drMyRow1 = dtMyTable.NewRow();
drMyRow1["TankName"] = "TK101";
drMyRow1["Height"] = 1;
drMyRow1["Volume"] = 12.4;
drMyRow1["Date"] = DateTime.UtcNow.AddDays(-1);

DataRow drMyRow2 = dtMyTable.NewRow();
drMyRow2["TankName"] = "TK101";
drMyRow2["Height"] = 2;
drMyRow2["Volume"] = 48.6;
drMyRow2["Date"] = DateTime.UtcNow.AddDays(-2);

dtMyTable.Rows.Add(drMyRow0);
dtMyTable.Rows.Add(drMyRow1);
dtMyTable.Rows.Add(drMyRow2);
dtMyTable.AcceptChanges();

// Set the Table and CachInterval Properties
// and Set the UOM for Volume
myTable.Table = dtMyTable;
myTable.CacheInterval = TimeSpan.FromMinutes(10);
myTable.SetExtendedProperty("Volume", "UOM", "US gal");
myTable.CheckIn();

// Display the table name and description
Console.WriteLine("Table Name = {0}", myTable.Name);
Console.WriteLine("Description = {0}", myTable.Description);
Console.WriteLine();

// Get the UOM for Volume
string uomName = myTable.GetExtendedProperty("Volume", "UOM") as string;
if (!String.IsNullOrEmpty(uomName))
{
    Console.WriteLine("UOM Property = {0}", uomName);
    Console.WriteLine();
}

// Display the DataTable
foreach (DataRow row in myTable.Table.Rows)
{
    Console.WriteLine("Tank Name = {0}", row["TankName"]);
    Console.WriteLine("  Height = {0}", row["Height"]);
    Console.WriteLine("  Volume = {0}", row["Volume"]);
    Console.WriteLine("  Date   = {0}", row["Date"]);
}

// The Table can be Refreshed Manually using AFTable.Refresh
myTable.Refresh();
' This example demonstrates how to import a table using an ADO.NET DataTable to create an
' internal table. It also demonstrates setting and getting the extended properties of an AFTable.

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

' Create a small Table using an ADO.NET DataTable
Dim dtMyTable As New DataTable()
dtMyTable.Locale = CultureInfo.CurrentCulture
Dim myTable As AFTable = myDB.Tables.Add("myTable")
myTable.TimeZone = AFTimeZone.UtcTimeZone
myTable.Description = "This is my table."

dtMyTable.Columns.Add("TankName", GetType(String))
dtMyTable.Columns.Add("Height", GetType(Double))
dtMyTable.Columns.Add("Volume", GetType(Double))
dtMyTable.Columns.Add("Date", GetType(DateTime))

Dim drMyRow0 As DataRow = dtMyTable.NewRow()
drMyRow0.Item("TankName") = "TK101"
drMyRow0.Item("Height") = 0.0#
drMyRow0.Item("Volume") = 0.0#
drMyRow0.Item("Date") = DateTime.UtcNow

Dim drMyRow1 As DataRow = dtMyTable.NewRow()
drMyRow1.Item("TankName") = "TK101"
drMyRow1.Item("Height") = 1.0#
drMyRow1.Item("Volume") = 12.4
drMyRow1.Item("Date") = DateTime.UtcNow.AddDays(-1)

Dim drMyRow2 As DataRow = dtMyTable.NewRow()
drMyRow2.Item("TankName") = "TK101"
drMyRow2.Item("Height") = 2.0#
drMyRow2.Item("Volume") = 48.6
drMyRow2.Item("Date") = DateTime.UtcNow.AddDays(-2)

dtMyTable.Rows.Add(drMyRow0)
dtMyTable.Rows.Add(drMyRow1)
dtMyTable.Rows.Add(drMyRow2)
dtMyTable.AcceptChanges()

' Set the Table and CachInterval Properties
' and Set the UOM for Volume
myTable.Table = dtMyTable
myTable.CacheInterval = TimeSpan.FromMinutes(10)
myTable.SetExtendedProperty("Volume", "UOM", "US gal")
myTable.CheckIn()

' Display the table name and description
Console.WriteLine("Table Name = {0}", myTable.Name)
Console.WriteLine("Description = {0}", myTable.Description)
Console.WriteLine()

' Get the UOM for Volume
Dim uomName As String = TryCast(myTable.GetExtendedProperty("Volume", "UOM"), String)
If Not String.IsNullOrEmpty(uomName) Then
    Console.WriteLine("UOM Property = {0}", uomName)
    Console.WriteLine()
End If

' Display the DataTable
For Each row As DataRow In myTable.Table.Rows
    Console.WriteLine("Tank Name = {0}", row("TankName"))
    Console.WriteLine("  Height = {0}", row("Height"))
    Console.WriteLine("  Volume = {0}", row("Volume"))
    Console.WriteLine("  Date   = {0}", row("Date"))
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


See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in