Which code segment chould you use?

You are creating a Windows Forms application. The application uses a SqlCommand object named cmd. The cmd object executes the following stored procedure.

CREATE PROCEDURE GetPhoneList
AS
BEGIN
SELECT CompnayName, Phone FROM Customers
SELECT CompanyName, Phone FROM Suppliers
END

You need to add all returned rows to the ListBox control named lstPhones. Which code segment chould you use?

You are creating a Windows Forms application. The application uses a SqlCommand object named cmd. The cmd object executes the following stored procedure.

CREATE PROCEDURE GetPhoneList
AS
BEGIN
SELECT CompnayName, Phone FROM Customers
SELECT CompanyName, Phone FROM Suppliers
END

You need to add all returned rows to the ListBox control named lstPhones. Which code segment chould you use?

A.
SqlDataReader rdr = cmd.ExecuteReader();
do {
while (rdr.Read()) {
lstPhones.Items.Add(rdr.GetString(0) + "t"
+rdr.GetString(1));
}
}while (rdr.NextResult());

B.
SqlDataReader rdr = cmdExecuteReader();
while (rdr.Read()) {
lstPhones.Items.Add(rdr.GetString(0) + "t"
+rdr.GetString(1));
}

C.
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.NextResult()) {
while (rdr.Read()) {
lstPhones.Items.Add(rdr.GetString(0) + "t"
+rdr.GetString(1));
}
}

D.
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.NextResult()) {
lstPhones.Items.Add(rdr.GetString(0) + "t"
+rdr.GetString(1));
}



Leave a Reply 0

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