Question from the Entity Framework test

How to get the first row of a SqlDataReader in C#

Hard

You are using Visual Studio 2010 and the .NET Framework 4.0 to create an application. This application connects to a SQL Server 2008 database. The database has a table dbo.Documents that contains a column with binary data. You are creating the data access layer.

You add the following code to query the dbo.Documents table.

01 public void LoadDocuments(DbConnection cnx)

02 {

03 var cmd = cnx.CreateCommand();

04 cmd.CommandText = "SELECT * FROM dbo.Documents";

05 ...

06 cnx.Open();

07

08 ReadDocument(reader);

09 }

You need to ensure that the data can be read into a stream (System.IO.Stream). What line of code should you insert at line 07?

Author: Guillaume BroutStatus: PublishedQuestion passed 191 times
Edit
0
Community Evaluations
developer avatar
Auteur anonyme
29/04/2024
var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); Cette option indique que les donnĂ©es binaires doivent ĂȘtre lues de maniĂšre sĂ©quentielle, ce qui est gĂ©nĂ©ralement nĂ©cessaire pour les donnĂ©es de grande taille telles que les donnĂ©es binaires stockĂ©es dans une base de donnĂ©es.