Microsoft Exam Questions

Which code segment should you insert at line 06?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. You create a DataSet object in the application.
You add two DataTable objects named App_Products and App_Categories to the DataSet.
You add the following code segment to populate the DataSet object.
(Line numbers are included for reference only.)

01 public void Fill(SqlConnection cnx, DataSet ds)
02 {
03 var cmd = cnx.CreateCommand();
04 cmd.CommandText = “SELECT * FROM dbo.Products; ” + “SELECT * FROM dbo.Categories”;
05 var adapter = new SqlDataAdapter(cmd);
06 …
07 }

You need to ensure that App_Products and App_Categories are populated from the dbo.Products and dbo.Categories database tables.
Which code segment should you insert at line 06?

A.
adapter.Fill(ds, “Products”);
adapter.Fill(ds, “Categories”);

B.
adapter.Fill(ds.Tables[“App_Products”]);
adapter.Fill(ds.Tables[“App_Categories”]);

C.
adapter.TableMappings.Add(“Table”, “App_Products”);
adapter.TableMappings.Add(“Table1”, “App_Categories”);
adapter.Fill(ds);

D.
adapter.TableMappings.Add(“Products”, “App_Products”);
adapter.TableMappings.Add(“Categories”, “App_Categories”);
adapter.Fill(ds);

Explanation:
Table Mapping in ADO.NET
(http://msdn.microsoft.com/en-us/library/ms810286.aspx)