创建新话题
已回答

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?


最佳答案

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

回答

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, 

登录 发表评论