PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database.
You use the following SQL statement to retrieve an instance of a DataSet object named ds:

SELECT CustomerID, CompanyName, ContactName, Address, City
FROM dbo.Customers

You need to query the DataSet object to retrieve only the rows where the ContactName field is not NULL. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
from row in ds.Tables[0].AsEnumerable()
where (string)row[“ContactName”] != null
select row;

B.
from row in ds.Tables[0].AsEnumerable()
where row.Field<string>(“ContactName”) != null
select row;

C.
from row in ds.Tables[0].AsEnumerable()
where !row.IsNull((string)row[“ContactName”])
select row;

D.
from row in ds.Tables[0].AsEnumerable()
where !Convert.IsDBNull(row.Field<string>(“ContactName”))
select row;

Explanation:
Field<T>(DataRow, String) Provides strongly-typed access to each of the column values in the specified row.
The Field method also supports nullable types.

2 Comments on “Which code segment should you use?


Leave a Reply