QUESTION 15
You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5.
You create a class that contains the following code segment. (Line numbers are included for reference only.)
01 public object GetCachedProducts(sqlConnection conn) {
02
03 if (Cache["products"] == null) {
04 SqlCommand cmd = new SqlCommand(
05 "SELECT * FROM Products", conn);
07 conn.Open();
08 Cache.Insert("products", GetData(cmd));
09 conn.Close();
10 }
11 return Cache["products"];
12 }
13
14 public object GetData(SqlCommand prodCmd) {
15
16 }
Each time a Web form has to access a list of products, the GetCachedProducts method is called to provide this list from the Cache object.
You need to ensure that the list of products is always available in the Cache object.
Which code segment should you insert at line 15?
A.return prodCmd.ExecuteReader();
SqlDataReader dr;
prodCmd.CommandTimeout = int.MaxValue;
B.dr = prodCmd.ExecuteReader();
return dr;
C.SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = prodCmd;
DataSet ds = new DataSet();
return ds.Tables[0];
D.SqlDataAdapter da = new SqlDataAdapter(prodCmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
Answer: D
QUESTION 16
You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5.
You write the following code segment in the code-behind file to create a Web form. (Line numbers are included for reference only.)
01 string strQuery = "select * from Products;"
02 + "select * from Categories";
03 SqlCommand cmd = new SqlCommand(strQuery, cnn);
04 cnn.Open();
05 SqlDataReader rdr = cmd.ExecuteReader();
06
07 rdr.Close();
08 cnn.Close();
You need to ensure that the gvProducts and gvCategories GridView controls display the data that is contained in the following two database tables:
The Products database tabl The Categories database tabl Which code segment should you insert at line 06?
A.gvProducts.DataSource = rdr;
gvProducts.DataBind();
gvCategories.DataSource = rdr;
gvCategories.DataBind();
B.gvProducts.DataSource = rdr;
gvCategories.DataSource = rdr;
gvProducts.DataBind();
gvCategories.DataBind();
C.gvProducts.DataSource = rdr;
rdr.NextResult();
gvCategories.DataSource = rdr;
gvProducts.DataBind();
gvCategories.DataBind();
D.gvProducts.DataSource = rdr;
gvCategories.DataSource = rdr;
gvProducts.DataBind();
rdr.NextResult();
gvCategories.DataBind();
Answer: D