IBM DB2 Application Development with Visual Studio .NET
Create a DatasetTwo new icons will appear on your screen for your db2ADP and DB2 Connection objects. Next, you need to create a Dataset, which is an in-memory database that stores the database-related information even after the connection is lost. Right click on your DataAdapter and choose generate Dataset as shown in Figure 10.
Figure 10. Right Click db2ADP and Choose Generate DatasetRename your Dataset to DB2DS1 for simplicity as shown in Figure 11.
Figure 11. Rename Your Dataset to DB2DS1
Add a Data Grid Control on the FormNow, you will place a data grid control on the form so the employee records display when the form loads:
- Add a data grid to the form and set its Dock property to Fill. Set its Data Source to db2DS11 and its Data Member to EMPLOYEE. Then set the forms startup position to "Center Screen" and border style to "Fixed Single".
- Open the code window and type the following code in the Form_Load event (this tutorial uses C#):
//Fill the Data Adapter db2Adp.Fill(db2DS11); //Set the Data Source of the DataGrid to the DataSet dataGrid1.DataSource = db2DS11; //Now bind the DataGrid with the Binding Option to display Employee Details from the Employee Table dataGrid1.SetDataBinding(db2DS11,"Employee");
- Run the application by pressing F5, and let DB2 and .NET work their magic for you (see Figure 12).
Figure 12. Employee Management System Results
You're Done!Voila! Now, wasnt that easy? You have now completed the tasks of configuring your data adapter, creating a dataset from it, establishing a connection to the SAMPLE database, and adding a data grid to the form. The result is a simple employee management system that harnesses DB2 and .NET.
About the AuthorAnil Mahadev is a database technologist and enthusiast with more than three years of experience with .NET and DB2. Reach him at firstname.lastname@example.org
Page 2 of 2