Which code segment should you insert at line 03?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application retrieves data from a Microsoft SQL Server 2008 database named AdventureWorks. The
AdventureWorks.dbo.ProductDetails table contains a column named ProductImages that uses a
varbinary(max) data type. You write the following code segment. (Line numbers are included for
reference only.)
01 SqlDataReader reader =
02 command.ExecuteReader(
03
04 );
05 while (reader.Read())
06 {
07 pubID = reader.GetString(0);
08 stream = new FileStream(
09 …
10 );
11 writer = new BinaryWriter(stream);
12 startIndex = 0;

13 retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
14 while (retval == bufferSize)
15 {
16 …
17 }
18 writer.Write(outByte, 0, (int)retval – 1);
19 writer.Flush();
20 writer.Close();
21 stream.Close();
22 }
You need to ensure that the code supports streaming data from the ProductImages column. Which
code segment should you insert at line 03?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application retrieves data from a Microsoft SQL Server 2008 database named AdventureWorks. The
AdventureWorks.dbo.ProductDetails table contains a column named ProductImages that uses a
varbinary(max) data type. You write the following code segment. (Line numbers are included for
reference only.)
01 SqlDataReader reader =
02 command.ExecuteReader(
03
04 );
05 while (reader.Read())
06 {
07 pubID = reader.GetString(0);
08 stream = new FileStream(
09 …
10 );
11 writer = new BinaryWriter(stream);
12 startIndex = 0;

13 retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
14 while (retval == bufferSize)
15 {
16 …
17 }
18 writer.Write(outByte, 0, (int)retval – 1);
19 writer.Flush();
20 writer.Close();
21 stream.Close();
22 }
You need to ensure that the code supports streaming data from the ProductImages column. Which
code segment should you insert at line 03?

A.
CommandBehavior.Default

B.
CommandBehavior.KeyInfo

C.
CommandBehavior.SingleResult

D.
CommandBehavior.SequentialAccess

Explanation:
Default
The query may return multiple result sets. Execution of the query may affect the database state.
Default sets no CommandBehavior flags, so calling ExecuteReader(CommandBehavior.Default)
is functionally equivalent to calling ExecuteReader().
KeyInfo The query returns column and primary key information. When KeyInfo is used for command
execution, the provider will append extra columns to the result set for existing primary key and
timestamp columns.
SingleResult The query returns a single result set.
SequentialAccess Provides a way for the DataReader to handle rows that contain columns with large
binary values.
Rather than loading the entire row, SequentialAccess enables the DataReader to load data as a
stream.
You can then use the GetBytes or GetChars method to specify a byte location to start the read
operation, and a limited buffer size for the data being returned.
CommandBehavior Enumeration
(http://msdn.microsoft.com/en-us/library/system.data.commandbehavior.aspx)



Leave a Reply 0

Your email address will not be published. Required fields are marked *