How to get every row value from particular column of a table in c# automation script.
Hi Niraj,
You can do this by getting the table keys first and then requesting the column value for every key.
For example:
public void Run(Engine engine)
{
ScriptDummy myElement = engine.GetDummy("Switch");string[] interfaceKeys = myElement.GetTablePrimaryKeys("Detailed Interface Info Main");
foreach(string key in interfaceKeys)
{
string interfaceMAC = Convert.ToString(myElement.GetParameterByPrimaryKey(50216, key));
}
}
Hi,
Below a simpler way using code library:
var dms = engine.GetDms();
var element = dms.GetElement("Element Name");
var table = element.GetTable(tableId);
var column = table.GetColumn<string>(columnId);
Hi Niraj,
It is possible to get all the values from a specific column using the classes available in the C# code blocks for automation scripts:
- First you will need to get all the keys from the table. For this purpose you will need to use GetTablePrimaryKeys (Element methods). This method will return the list of keys in a string array
- Next, using an iterator (e.g. a for loop or foreach) you will need to get the value from a specific column. For this purpose you could use either GetParameterByPrimaryKey or GetParameterDisplayByPrimaryKey (Element methods). The last method could be used for example when the column contains discreet values (it will return the displayed value)
Please find below an example:
ScriptDummy dummyElement = engine.GetDummy("dummyElement");
string[] saKeys = dummyElement.GetTablePrimaryKeys(/*TABLE_PID*/1000);
object[] oColumnValue= new object[saKeys.Length];
for(int i=0 ; i< saKeys.Length; i++)
{
oColumnValue[i] = dummyElement.GetParameterByPrimaryKey(/*COLUMN_PID*/1002, saKeys[i]);
}