Click or drag to resize
OSIsoft, LLC

AFTableTable Property

This property provides access to the cached data of a table.

Namespace:  OSIsoft.AF.Asset
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version:
public DataTable Table { get; set; }

Property Value

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

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.

// 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);


// 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");

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

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

// 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
Version Information


Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6, 2.5, 2.4
See Also
Enabling Operational Intelligence