Which code segment should you use?

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

You write the following code segment.

string queryString = "Select Name, Age from dbo.Table_1";
SqlCommand command = new SqlCommand(queryString, (SqlConnection)connection));

You need to get the value that is contained in the first column of the first row of the result set returned by the query.

Which code segment should you use?

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

You write the following code segment.

string queryString = "Select Name, Age from dbo.Table_1";
SqlCommand command = new SqlCommand(queryString, (SqlConnection)connection));

You need to get the value that is contained in the first column of the first row of the result set returned by the query.

Which code segment should you use?

A.
var value = command.ExecuteScalar();
string requiredValue = value.ToString();

B.
var value = command.ExecuteNonQuery();
string requiredValue = value.ToString();

C.
var value = command.ExecuteReader(CommandBehavior.SingleRow);
string requiredValue = value[0].ToString();

D.
var value = command.ExecuteReader(CommandBehavior.SingleRow);
string requiredValue = value[1].ToString();



Leave a Reply 0

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