Download presentation
Presentation is loading. Please wait.
Published byFerdinand Bryan Modified over 8 years ago
1
ADO.NET Objects Data Adapters Dr. Ron Eaglin
2
Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation of working with Database Command objects Working with Data Adapters Working with Data Sets
3
Data Adapter Data Adapter is the glue between the database and a dataset.
4
Data Adapter Data Adapters encapsulate code and functionality to –Select –Update –Insert –delete.
5
Design Time Data Adapter If SQLDataAdapter is not in your toolbox, add it by using “Choose items …” Drag the SQLDataAdapter onto your form.
6
Design Time Data Adapter
8
We will have the adapter Wizard generate stored Procedures.
9
Design Time Data Adapter
11
Name the stored procedures to fit The naming convention that you are Using in your database You may review the SQL script that Will be executed to create the stored Procedures.
12
Design Time DataAdapter This SQL Script will be run to create the Stored procedures used by the data Adapter.
13
Design Time Data Adapters
14
SQL Server Note the additional stored Procedures are now added to The list of stored procedures In the database.
15
SQLDataAdapter properties Note that the Data Adapter also created four command objects
16
Create the Dataset A Dataset is now necessary to handle the actual data. A Dataset is an in-memory object that “mirrors” the database. A dataset can contain tables, columns, fields.
17
Create the Dataset The Dataset can also be generated by A wizard. Click on Generate Dataset when The Data Adapter is selected in the form.
18
Created Dataset The Dataset now exists in the project
19
Add Code to Project Add button to project
20
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.SqlDataAdapter1.Fill(Me.PersonAddressDataset1) Dim i, j As Integer Dim TN, CN As String For i = 1 To Me.PersonAddressDataset1.Tables.Count TN = Me.PersonAddressDataset1.Tables(i - 1).TableName For j = 1 To PersonAddressDataset1.Tables(i - 1).Columns.Count CN = PersonAddressDataset1.Tables(i - 1).Columns(j - 1).ColumnName ListBox1.Items.Add(TN + " : " + CN) Next j Next i End Sub
21
Results of Code
22
Using Bindable Objects Add DataGridView
23
Setting Datagrid Properties Using the properties window use the drop-down On the DataSource property
24
Note the addition of the Binding Source
25
Binding Source In the DataGridView properties select the DataMember property and select SelectPersonAddress
27
Run Application When the Dataset is filled The bound grid automatically Populates.
28
Updating database Add button to application
29
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.SqlDataAdapter1.Update(Me.PersonAddressDataset1) End Sub
30
Make changes
31
Test the Update If update was successful the record will be changed. Close and re-open project and load dataset – was change persistent?
32
Review Creating a data adapter Using wizards to configure adapter Creating a Dataset Filling set from adapter Displaying data and table info Updating from bound object
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.