PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 08?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application uses data from a Microsoft SQL Server 2005 database.

You write the following code segment. (Line numbers are included for reference only.)

01 public IDataReader GetCustomerReader()
02 {
03 SqlConnection con = new SqlConnection();
04 //Set up the connection
05 con.Open();
06 string sql = "Select * from Customers";
07 IDataReader rd = null;
08
09 con.Close();
10 return rd;
11 }

You need to ensure that a DataReader stream for the data in the Customers table can be returned from the GetCustomerReader method.

Which code segment should you insert at line 08?

PrepAway - Latest Free Exam Questions & Answers

A.
SqlCommand cmd = new SqlCommand(sql, con);
rd = cmd.ExecuteReader(CommandBehavior.SingleResult);

B.
SqlCommand cmd = new SqlCommand(sql, con);
rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);

C.
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.Fill(ds);
rd = ds.CreateDataReader();

D.
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.FillSchema(ds, SchemaType.Source, "Customers");
rd = ds.Tables["Customers"].CreateDataReader();


Leave a Reply