Which code segment should you add at line 06?

You are creating a Windows Forms application by using the .NET Framework 3.5.
You write the following code segment to bind a list of categories to a drop-down list. (Line numbers are included for reference only.)

01 OleDbConnection cnnNorthwind = new OleDbConnection(connectionString);
02 OleDbCommand cmdCategory = new OleDbCommand( "SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryName", cnnNorthwind);
03 OleDbDataAdapter daCategory = new OleDbDataAdapter(cmdCategory);
04 DataSet dsCategory = new DataSet();
05 daCategory.Fill(dsCategory);
06

You need to ensure that the drop-down list meets the following requirements:
* Displays all category names.
* Uses the category ID as the selected item value.
Which code segment should you add at line 06?

You are creating a Windows Forms application by using the .NET Framework 3.5.
You write the following code segment to bind a list of categories to a drop-down list. (Line numbers are included for reference only.)

01 OleDbConnection cnnNorthwind = new OleDbConnection(connectionString);
02 OleDbCommand cmdCategory = new OleDbCommand( "SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryName", cnnNorthwind);
03 OleDbDataAdapter daCategory = new OleDbDataAdapter(cmdCategory);
04 DataSet dsCategory = new DataSet();
05 daCategory.Fill(dsCategory);
06

You need to ensure that the drop-down list meets the following requirements:
* Displays all category names.
* Uses the category ID as the selected item value.
Which code segment should you add at line 06?

A.
ddlCategory.DataSource = dsCategory;
ddlCategory.DisplayMember = "CategoryName";ddlCategory.ValueMember = "CategoryID";

B.
ddlCategory.DataSource = dsCategory.Tables[0];ddlCategory.DisplayMember = "CategoryName";
ddlCategory.ValueMember = "CategoryID";

C.
ddlCategory.DataBindings.Add("DisplayMember", dsCategory,
"CategoryName");ddlCategory.DataBindings.Add("ValueMember", dsCategory, "CategoryID");

D.
ddlCategory.DataBindings.Add("DisplayMember", dsCategory.Tables[0], "CategoryName");
ddlCategory.DataBindings.Add("ValueMember", dsCategory.Tables[0], "CategoryID");



Leave a Reply 0

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