Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any.

Similar presentations


Presentation on theme: "1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any."— Presentation transcript:

1 1 Databound Controls

2 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any C# code.

3 3 References Beginning Visual C# 2005 Karli Watson, et al. Wrox Press, 2006 Chapter 25 Unchanged in Visual C# 2008

4 4 Northwind Traders Database Add the Northwind Traders database tables to your database on scorpius. Download SQL script to build tables: http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/ http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/ File add_northwind_tables.sql Open a command prompt window and run sqlcmd to execute the script. See next slide.

5 5 Execute the Script

6 6 Check Tables in Server Explorer

7 7 High Level Components Data Source Encapsulates Connection and Command objects. Databound Textbox Automatic updates both directions DataGridView Display entire table in grid format Automatic updates both directions

8 8 ProductData Application We will create a new version of the Northwind Product Browser using high level components. SQL Data Source Databound Textboxes Databound DataGridView No C# code!

9 9 ProductData Application Create a new C# Windows Forms Application. Name: ProductData Set form1 text property to Product Data DO NOT rename form1 On the following slides we will: Add a DataSource to the form. Configure to access Products table. Add databound textboxes for data.

10 10 ProductData Application

11 11 Form1

12 12 Add a Data Source On the Data menu, select Add New Data Source.

13 13 Data Source Configuration Wizard

14 14 Data Source Configuration Wizard Select connection to your SQL Server database. Or create a new connection if necessary.

15 15 Data Source Configuration Wizard

16 16 Data Source Configuration Wizard Expand Tables, then Products. Select columns. Click Finish.

17 17 DataSet in Solution Explorer

18 18 Show Data Sources To add databound controls to the form, select Show Data Sources on the Data menu

19 19 Show Data Sources

20 20 Adding a DataSet to the Program Expand Products. Drag ProductName to design surface.

21 21 Adding a DataSet to the Program Build and run.

22 22 App Running Note navigation controls.

23 23 Add Data to Form Drag other columns to the design surface. Arrange and resize labels and textboxes. Build and run

24 24 Add Data to Form

25 25 App Running End of Section Note that you can update the data and save it back to the database. Click the floppy disk icon to save.

26 26 Using a DataGridView The DataGridView allows us to display an entire table as a grid. DataBinding permits all work to be done at design time. No C# code required!

27 27 Using a DataGridView Create a new project called Product_Grid Set form1 Text property to Northwind Products. DO NOT rename form1. Add a data source as before. Same configuration. Show Data Sources.

28 28 Using a DataGridView Drag the Products Table to the design surface.

29 29 Using a DataGridView Resize the form and the data grid.

30 30 Using a DataGridView Anchor the data grid on all four sides. Build and run.

31 31 Products_Datagrid Running

32 32 Update Note that we can update data shown on the grid. Clicking the “Save” icon will update the database.

33 33 Summary Databound Controls permit us to create an data driven application with zero code. Just configure high level components. Internally these controls use the low level ADO classes that we saw previously.


Download ppt "1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any."

Similar presentations


Ads by Google