Start a new topic
Answered

How do I return a DataTable instead of IswItems?

Can you provide an example of how to call GetItemsAsDataTable? Can it be used with a single item or only with the complete data set?


Best Answer

Hello Stacey, 


There are two API functions that return a DataTable instead of IswItems.

One operates on the complete database and uses filter.

 

DataTable dt = SWConnection.Instance.Broker.Q.GetItemsAsDataTable("<Filter/>", new[] { "Name", "Version" });

 

This command creates a DataTable with one row per item in the database. Each row will have two columns containing the name and version of the item.

To create the filter string, you can use the “General search” dialog from the “Open item” menu and view the XML tab.

 

image

 

The other uses a start item and a path expression to find objects related to the starting item.

 

IswItem startItem = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000000432"));

DataTable dt = SWConnection.Instance.Broker.Q.ExecutePathAsDataTable(startItem, "/DFR", new string[] { "Name", "Version" });

 

This example will return a DataTable with one row for each item that is referenced by the part type “DFR” from the starting item.

Please see the Help for information on path expressions.

 

Both of these commands can potentially be very expensive performance-wise on the server.

 

If you want to work with the found items (update and save back to the server), you should use the functions ExecutePathAsItems or GetItems which returns SystemWeaver objects instead.  


Best regards, 

1 Comment

Answer

Hello Stacey, 


There are two API functions that return a DataTable instead of IswItems.

One operates on the complete database and uses filter.

 

DataTable dt = SWConnection.Instance.Broker.Q.GetItemsAsDataTable("<Filter/>", new[] { "Name", "Version" });

 

This command creates a DataTable with one row per item in the database. Each row will have two columns containing the name and version of the item.

To create the filter string, you can use the “General search” dialog from the “Open item” menu and view the XML tab.

 

image

 

The other uses a start item and a path expression to find objects related to the starting item.

 

IswItem startItem = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000000432"));

DataTable dt = SWConnection.Instance.Broker.Q.ExecutePathAsDataTable(startItem, "/DFR", new string[] { "Name", "Version" });

 

This example will return a DataTable with one row for each item that is referenced by the part type “DFR” from the starting item.

Please see the Help for information on path expressions.

 

Both of these commands can potentially be very expensive performance-wise on the server.

 

If you want to work with the found items (update and save back to the server), you should use the functions ExecutePathAsItems or GetItems which returns SystemWeaver objects instead.  


Best regards, 

Login to post a comment