1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and...
-
Upload
herbert-lane -
Category
Documents
-
view
212 -
download
0
Transcript of 1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and...
![Page 1: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/1.jpg)
1
Databound Controls
![Page 2: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/2.jpg)
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.
![Page 3: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/3.jpg)
3
References
Beginning Visual C# 2005 Karli Watson, et al. Wrox Press, 2006
Chapter 25
Unchanged in Visual C# 2008
![Page 4: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/4.jpg)
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_Develo
pment/Downloads/ File add_northwind_tables.sql
Open a command prompt window and run sqlcmd to execute the script.
See next slide.
![Page 5: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/5.jpg)
5
Execute the Script
![Page 6: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/6.jpg)
6
Check Tables in Server Explorer
![Page 7: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/7.jpg)
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
![Page 8: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/8.jpg)
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!
![Page 9: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/9.jpg)
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.
![Page 10: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/10.jpg)
10
ProductData Application
![Page 11: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/11.jpg)
11
Form1
![Page 12: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/12.jpg)
12
Add a Data SourceOn the Data menu, select Add New Data Source.
![Page 13: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/13.jpg)
13
Data Source Configuration Wizard
![Page 14: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/14.jpg)
14
Data Source Configuration Wizard
Select connection to your SQL Server database.
Or create a new connection if necessary.
![Page 15: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/15.jpg)
15
Data Source Configuration Wizard
![Page 16: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/16.jpg)
16
Data Source Configuration Wizard
Expand Tables, then Products. Select columns. Click Finish.
![Page 17: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/17.jpg)
17
DataSet in Solution Explorer
![Page 18: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/18.jpg)
18
Show Data Sources
To add databound controls to the form, select Show Data Sources on the Data menu
![Page 19: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/19.jpg)
19
Show Data Sources
![Page 20: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/20.jpg)
20
Adding a DataSet to the Program
Expand Products. Drag ProductName to design surface.
![Page 21: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/21.jpg)
21
Adding a DataSet to the Program
Build and run.
![Page 22: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/22.jpg)
22
App Running
Note navigation controls.
![Page 23: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/23.jpg)
23
Add Data to Form
Drag other columns to the design surface.
Arrange and resize labels and textboxes.
Build and run
![Page 24: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/24.jpg)
24
Add Data to Form
![Page 25: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/25.jpg)
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.
![Page 26: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/26.jpg)
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!
![Page 27: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/27.jpg)
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.
![Page 28: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/28.jpg)
28
Using a DataGridView
Drag the Products Table to the design surface.
![Page 29: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/29.jpg)
29
Using a DataGridView
Resize the form and the data grid.
![Page 30: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/30.jpg)
30
Using a DataGridView
Anchor the data grid on all four sides. Build and run.
![Page 31: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/31.jpg)
31
Products_Datagrid Running
![Page 32: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/32.jpg)
32
Update
Note that we can update data shown on the grid.
Clicking the “Save” icon will update the database.
![Page 33: 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.](https://reader035.fdocuments.in/reader035/viewer/2022070409/56649e985503460f94b9afc0/html5/thumbnails/33.jpg)
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.