Which code segment should you use?

You are developing an application that retrieves a list of geographical regions from a table in a Microsoft SQL Server database. The list of regions is displayed in a drop-down list box on a Windows Form.

You want to populate the list box with data from a DataSet object. You want to fill the DataSet object by using a SqlDataAdapter object.

You create a SqlConnection object named myConnection and a SQL query string named regionSQL. You need to write the code to create the SqlDataAdapter object.

Which code segment should you use?

You are developing an application that retrieves a list of geographical regions from a table in a Microsoft SQL Server database. The list of regions is displayed in a drop-down list box on a Windows Form.

You want to populate the list box with data from a DataSet object. You want to fill the DataSet object by using a SqlDataAdapter object.

You create a SqlConnection object named myConnection and a SQL query string named regionSQL. You need to write the code to create the SqlDataAdapter object.

Which code segment should you use?

A.
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand.Connection = myConnection;
myDataAdapter.SelectCommand.CommandText = regionSQL;

B.
SqlDataAdapter myDataAdapter = new
SqlDataAdapter(regionSQL, myConnection);

C.
SqlCommand SqlCmd = new SqlCommand(regionSQL);
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand.Connection= myConnection;
myDataAdapter.SelectCommand = SqlCmd;

D.
SqlCommand SqlCmd = new SqlCommand();
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
SqlCmd.CommandText = regionSQL;
myDataAdapter.SelectCommand.Connection= myConnection;
myDataAdapter.SelectCommand = SqlCmd;



Leave a Reply 0

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