What should you do to find the cause of the exception being raised in line 05?

You create a Web Form that displays a GridView. The GridViews data source is a DataSet named dsOrders. The DataSet contains two DataTables named Orders and OrderDetails. You create a relation between the two DataTables using the following code segment. (Line numbers are included for reference only.)

01 dtOrders =dsOrders.Tables("Orders")
02 dtOrderDetails = dsOrders.Tables("OrderDetails") 03 colParent = dtOrders.Columns("OrderID")
04 colChild =dtOrderDetails.Columns("ParentOrderID") 05 dsOrders.Relations.Add("Rel1", colParent,colChild, False)

You need to find the cause of the exception being raised in line 05.
What should you do?

You create a Web Form that displays a GridView. The GridViews data source is a DataSet named dsOrders. The DataSet contains two DataTables named Orders and OrderDetails. You create a relation between the two DataTables using the following code segment. (Line numbers are included for reference only.)

01 dtOrders =dsOrders.Tables(“Orders”)
02 dtOrderDetails = dsOrders.Tables(“OrderDetails”) 03 colParent = dtOrders.Columns(“OrderID”)
04 colChild =dtOrderDetails.Columns(“ParentOrderID”) 05 dsOrders.Relations.Add(“Rel1”, colParent,colChild, False)

You need to find the cause of the exception being raised in line 05.
What should you do?

A.
Ensure that the child column and the parent column have the same names.

B.
Ensure that the child table and the parent table have the same names.

C.
Ensure that the child column and the parent column have the same data types.

D.
Ensure that each row in the child table has a corresponding row in the parent table.

E.
Ensure that the tables have an explicit relationship defined by a foreign key constraint in the database.

Explanation:

Answer D is correct cause its true. If a row in the child table does not have a corresponding row in the parent table an exception is thrown. Not B: Answer B would be incorrect because DataRelations are allowed between tables that have different names. Actually this is the scenario most of the times.



Leave a Reply 0

Your email address will not be published. Required fields are marked *