You are creating a Windows Forms application by using the .NET Framework 3.5.
You need to populate a list box control along with category names by using a DataReader control.
Which code segment should you use?
A.
OleDbDataReader reader;OleDbConnection cnnNorthwind = new OleDbConnection( connectionString);cnnNorthwind.Open();
OleDbCommand cmdCategory = new OleDbCommand( "SELECT * FROM Categories", cnnNorthwind);
reader = cmdCategory.ExecuteReader();
while (reader.Read()) {
lbCategories.Items.Add(reader["CategoryName"]);
}
cnnNorthwind.Close();
B.
OleDbDataReader reader;OleDbConnection cnnNorthwind = new OleDbConnection( connectionString);cnnNorthwind.Open();
OleDbCommand cmdCategory = new OleDbCommand( "SELECT * FROM Orders", cnnNorthwind);
reader = cmdCategory.ExecuteReader();
while (reader.NextResult()) {
lbCategories.Items.Add(reader["CategoryName"]);
}
cnnNorthwind.Close();
C.
OleDbDataReader reader;OleDbConnection cnnNorthwind = new OleDbConnection( connectionString);cnnNorthwind.Open();
OleDbCommand cmdCategory = new OleDbCommand( "SELECT * FROM Orders", cnnNorthwind);
reader = cmdCategory.ExecuteReader();cnnNorthwind.Close();
while (reader.Read()) {
lbCategories.Items.Add(reader["CategoryName"]);
}
cnnNorthwind.Close();
D.
OleDbDataReader reader;using (OleDbConnection cnnNorthwind = new OleDbConnection( connectionString)) { cnnNorthwind.Open();
OleDbCommand cmdCategory = new OleDbCommand( "SELECT * FROM Orders", cnnNorthwind);
reader = cmdCategory.ExecuteReader();}
while (reader.Read()) {
lbCategories.Items.Add(reader["CategoryName"]);
}
cnnNorthwind.Close();