You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET.The application contains a DataSet object named OrderDS that has the Order and
OrderDetail tables as shown in the following exhibit.
You write the following code segment. (Line numbers are included for reference only.)
01 private void GetOrders(SqlDataConnection cn) {
02 SqlCommand cmd = cn.CreateCommand();
03 cmd.CommandText = “Select * from [Order];
Select * from [OrderDetail];”;
04 SqlDataAdapter da = new SqlDataAdapter(cmd);
05
06 }
You need to ensure that the Order and the OrderDetail tables are populated. Which code
segment should you insert at line 05?
A.
da.Fill(OrderDS);
B.
da.Fill(OrderDS.Order);
da.Fill(OrderDS.OrderDetail);
C.
da.TableMappings.AddRange(new DataTableMapping[] {new
DataTableMapping(“Table”, “Order”),
new DataTableMapping(“Table1”, “OrderDetail”)});
da.Fill(OrderDS);
D.
DataTableMapping mapOrder = new DataTableMapping();
mapOrder.DataSetTable = “Order”;
DataTableMapping mapOrderDetail = new DataTableMapping();
mapOrder.DataSetTable = “OrderDetail”;
da.TableMappings.AddRange(new DataTableMapping[] { mapOrder, mapOrderDetail });
da.Fill(OrderDS);
Explanation:
The syntax for creating a new DataTableMapping is the following:
DataTableMapping dtMap = new DataTableMapping(string sourceTable, string dataSetTable);
Answer choice C has the mapping order reversed.