Which code segment should you use?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
The application has an untyped DataTable object named tblCustomer.
The tblCustomer object contains a DataColumn named Age.
You plan to create a ColumnChanging event handler for the tblCustomer object. You need to ensure that when the existing data is modified, any value in the Age DataColumn that is greater than 100 is set to DBNull.
Which code segment should you use?
Which line of code should you insert at line 19?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.
The application adds data to a table named Customer. The Customer table has a primary key column.
You write the following code segment. (Line numbers are included for reference only.)
01 void ValidateData(DataTable tbl)
02 {
03 tbl.Columns.Add("IsValid", typeof(Boolean));
04 foreach (DataRow item in tbl.Rows)
05 {
06 //Set IsValid to true or false
07 }
08 }
09 DataTable ChangeData()
10 {
11 SqlDataAdapter adp = new SqlDataAdapter();
12 //Setup SqlDataAdapter to get Customer data
13 DataTable tblOriginal = new DataTable();
14 adp.FillSchema(tblOriginal, SchemaType.Source);
15 adp.Fill(tblOriginal);
16 //Change customer details
17 DataTable tblNew = tblOriginal.GetChanges();
18 ValidateData(tblNew);
19
20 return tblOriginal;
21 }
You need to ensure that the ChangeData method returns a DataTable that includes the value in the IsValid column for each row in the Customer table.
Which line of code should you insert at line 19?
Which code segment should you use?
You create an application by using the Microsoft .NET Framework version 3.5. You use Microsoft ADO.NET to access data for the application.
The application connects to a Microsoft SQL Server 2005 database. The database contains invoice records of customers in the Customer and Invoice tables.
You write the following code segment.
DataSet ds = new DataSet();
DataTable tblCust = ds.Tables.Add("Customer");
DataTable tblInv = ds.Tables.Add("Invoice");
DataColumn colPar = tblCust.Columns.Add("ID", typeof(int));
tblCust.Constraints.Add("PKey", colPar, true);
tblInv.Columns.Add("InvNo", typeof(string));
DataColumn colChild = tblInv.Columns.Add("CustomerID", typeof(int));
DataRow[] relatedRows;
//Retrieve data for Customer and Invoice
You need to retrieve the invoice details from the tblInv DataTable for customer records that have a value 1 in the ID column of the tblCust DataTable.
Which code segment should you use?
Which code segment should you use?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
You write the following code segment.
DataTable tbl = new DataTable();
DataColumn colId = tbl.Columns.Add("ID", typeof(int));
colId.AutoIncrement = true;
tbl.Constraints.Add("Pkey", colId, true);
DataColumn colCtry = tbl.Columns.Add("Country", typeof(string));
colCtry.DefaultValue = "USA";
tbl.Columns.Add("Name", typeof(string));
You need to create a new row in the tbl DataTable that meets the following requirements:
The ID column is set to an auto-incremented value.
The Country column is set to the default value.
The Name column is set to the value "Customer A".
Which code segment should you use?
Which code segment should you use?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
You write the following code segment.
DataTable tblInvDet = new DataTable("InvoiceDetail");
DataColumn colInvNo = tblInvDet.Columns.Add("InvNo", typeof(string));
DataColumn colItemNo = tblInvDet.Columns.Add("ItemNo", typeof(int));
You need to ensure that the corresponding values in the InvNo DataColumn and the ItemNo DataColumn form a unique pair.
Which code segment should you use?
Which code segment should you use?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
You write the following code segment.
DataTable tblCustomer = new DataTable("Customer");
DataColumn parentCol= tblCustomer.Columns.Add("ID", typeof(int));
//Other columns added for tblCustomer
DataTable tblOrder = new DataTable("Order");
DataColumn childCol=tblOrder.Columns.Add("CustomerID",typeof(int));
//Other columns added for tblOrder
DataSet ds = new DataSet();
ds.Tables.Add(tblOrder);
ds.Tables.Add(tblCustomer);
The CustomerID column relates the Order DataTable to the Customer DataTable. You need to ensure that when you delete a row in the Customer DataTable, the corresponding row in the Order DataTable is deleted.
Which code segment should you use?
Which code segment should you use?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.
You write the following code segment.
string sql = "Select InvoiceNo,OrderAmount from Orders";
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataTable tblOrders = new DataTable();
adp.Fill(tblOrders);
If the value of the OrderAmount column is greater than 1000, then a discount of 5 percent is calculated.
You need to create a DataColumn object named Discount that contains the discount value for each row in the tblOrders DataTable.
Which code segment should you use?
Which code segment should you insert at line 13?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.
You write the following code segment. (Line numbers are included for reference only.)
01 SqlConnection sqlconn
02 …
03 SqlDataAdapter ordAdapter =
04 new SqlDataAdapter(
05 SELECT OrderID, CustomerID, OrderDate, Qty, UnitPrice,"+
06 "UnitMargin FROM Sales.SalesOrderDetail", sqlconn);
07 DataSet ord_ds = new DataSet();
08 DataTable ord_dt = ord_ds.Tables.Add("Orders");
09 ordAdapter.Fill(ord_dt);
10 ord_dt.Rows[0].BeginEdit();
11 // The code here will insert, update and delete rows to the ord_dt DataTable.
12 ord_dt.Rows[0].EndEdit();
13
14 ord_dt.AcceptChanges();
You need to validate that every row that has the Qty column value is set to zero before you commit any changes.
Which code segment should you insert at line 13?
Which code segment should you add?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.
You write the following code segment.
SqlConnection sqlconn;
…
SqlDataAdapter custAdapter = new SqlDataAdapter("SELECT CustID, CompanyName FROM Sales.Customer", sqlconn);
SqlDataAdapter ordAdapter = new SqlDataAdapter("SELECT OrderID, CustID, OrderDate FROM "+ "Sales.SalesOrderDetail", sqlconn);
DataSet customerOrders = new DataSet();
custAdapter.Fill(customerOrders, "Customers");
ordAdapter.Fill(customerOrders, "Orders");
You need to ensure that the output of the customerOrders DataSet matches the XML schema of the following code fragment.
<CustomerOrders>
<Customers>
<CustID>ALFKI</CustID>
<CompanyName>Alfreds Futterkiste</CompanyName>
</Customers>
<Orders>
<OrderID>10643</OrderID>
<CustID>ALFKI</CustID>
<OrderDate>1997-08-25T00:00:00</OrderDate>
</Orders>
<Orders>
<OrderID>10692</OrderID>
<CustID>ALFKI</CustID>
<OrderDate>1997-10-03T00:00:00</OrderDate>
</Orders>
</CustomerOrders>
Which code segment should you add?
Which line of code should you insert at line 14?
You create an application by using the Microsoft .NET Framework 3.5 and Microsoft Synchronization Services for Microsoft ADO.NET.
The application uses a Microsoft SQL Server 2005 (Compact Edition) database. This database contains a table named Order. Microsoft Windows Mobilebased devices synchronize data concurrently with the database server.
You write the following code segment. (Line numbers are included for reference only.)
01 public class ServerSyncProvider : DbServerSyncProvider
02 {
03 public ServerSyncProvider()
04 {
05 SyncAdapter orderSyncAdapter =
06 new SyncAdapter("Order");
07 SqlCommand ManageRows = new SqlCommand();
08 ManageRows.CommandText =
09 "DELETE FROM dbo.Order WHERE OrderId = @OrderId " +
10 "AND ((UpdateTS <= @sync_last_received_anchor OR " +
11 "UpdateId = @sync_client_id ) OR @sync_force_write=1) " +
12 "IF (@@rowcount > 0) UPDATE Sales. Order_Tombstone SET "+
13 "DeleteId = @sync_client_id WHERE OrderId = @OrderId";
14
15 }
16 }
You need to ensure that the application performs the following tasks:
It allows bidirectional incremental data changes to the Order table.
It generates the ClientUpdateServerDelete action as a conflict.
Which line of code should you insert at line 14?