You use Visual Studio .NET to develop a Windows based application that interacts with a Microsoft SQL Server database. The form CustomerForm contains a SqlConnection named XYZConnection, a SqlDataAdapter named XYZDataAdapter, a DataSet named XYZDataSet, and several TextBox controls bound to columns in XYZDataSet. The application connects successfully, but no data appears in the text boxes. During the CustomerForm.Load event, which action must occur so that the bound text boxes display data from the database?
Certification
Microsoft Certification
Difficulty: Medium
Choose an option
-
AExecute the BeginInit method of XYZDataSet during form load
-
BExecute the Open method of XYZConnection during form load
-
CExecute the FillSchema method of XYZDataAdapter and pass XYZDataSet
-
DExecute the Fill method of XYZDataAdapter and pass XYZDataSet
Answer
Correct Answer: Execute the Fill method of XYZDataAdapter and pass XYZDataSet
Explanation
Introduction / Context:In a Windows Forms application that uses ADO.NET, data binding between controls and a DataSet object is very common. However, binding the controls at design time is not enough. The DataSet must actually be filled with data at runtime. This question checks whether you understand which ADO.NET method is responsible for moving data from the database into the DataSet so that bound controls such as TextBox controls show values.Given Data / Assumptions:
- There is a SqlConnection named XYZConnection.
- There is a SqlDataAdapter named XYZDataAdapter configured with a valid SELECT command.
- There is a DataSet named XYZDataSet with a DataTable that matches the result set.
- TextBox controls are bound to columns in XYZDataSet using the DataBindings property.
- The application connects to the database without connection errors, but the text boxes remain empty.