Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database. You load records from the Customers table
into a DataSet object named dataset. You need to retrieve the value of the City field from the first
and last records in the Customers table. Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database. You load records from the Customers table
into a DataSet object named dataset. You need to retrieve the value of the City field from the first
and last records in the Customers table. Which code segment should you use?

A.
DataTable dt = dataset.Tables[“Customers”];
string first = dt.Rows[0][“City”].ToString();
string last = dt.Rows[dt.Rows.Count – 1][“City”].ToString();

B.
DataTable dt = dataset.Tables[“Customers”];
string first = dt.Rows[0][“City”].ToString();
string last = dt.Rows[dt.Rows.Count][“City”].ToString();

C.
DataRelation relationFirst = dataset.Relations[0];
DataRelation relationLast = dataset.Relations[dataset.Relations.Count – 1];
string first = relationFirst.childTable.Columns[“City”].ToString();
string last = relationLast.childTable.Columns[“City”].ToString();

D.
DataRelation relationFirst = dataset.Relations[0];
DataRelation relationLast = dataset.Relations[dataset.Relations.Count];
string first = relationFirst.childTable.Columns[“City”].ToString();
string last = relationLast.childTable.Columns[“City”].ToString();



Leave a Reply 0

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