which is registered on the system where the application is running?

You are busy adding a ComboBox control name testComboBox to a form. Which code segment should you use to populate the ComboBox with a list of valid Microsoft SQL Server instances which is registered on the system where the application is running?

You are busy adding a ComboBox control name testComboBox to a form. Which code segment should you use to populate the ComboBox with a list of valid Microsoft SQL Server instances which is registered on the system where the application is running?

A.
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSource[];
testComboBox.DataSource = dataTable;
testComboBox.DisplayMember = @"{ServerName}{InstanceName}";
testComboBox.ValueMember = "InstanceName";
testComboBox.FormatString = "{0}{1}";

B.
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSource[];
Foreach [DataRow row in dataTable.Rows]
{
string dataSource = [string] row["InstanceName"];
if [row["InstanceName"] != DBNull.Value]
{
dataSource += string.Format@"{0}",row["ServerName"]]’
}
testComboBox.Items.Add[dataSource];
}

C.
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSource[];
testComboBox.DataSource = dataTable;
testComboBox.DisplayMember = "ServerName";
testComboBox.ValueMember = "InstanceName";

D.
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSource[];
Foreach [DataRow row in dataTable.Rows]
{
string dataSource = [string] row["ServerName"];
if [row["InstanceName"] != DBNull.Value]
{
dataSource += string.Format@"{0}",row["InstanceName"]]’
}
testComboBox.Items.Add[dataSource];
}

Explanation:
The SqlDataSourceEnumerator class permits you to enumerate registered SQL server instances. If you want to get hold of the instance, you should call the GetDataSource method. This will return an instance of four columns.

Incorrect Answers:
B, C, D: You do not need to set the DataSource property of testComboBox to the DataTable instance returned from GetDataSource. This will not display the values from the ServerName and InstanceName field as a single value.



Leave a Reply 0

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