Docsity

Databases Two - Advanced Programming - Lecture Slides, Slides of Advanced Computer Programming

Partial preview of the text

Download Databases Two - Advanced Programming - Lecture Slides and more Slides Advanced Computer Programming in PDF only on Docsity!

Working with Databases

C# Programming: From Problem Analysis to Program Design 3 rd^ Edition

Part II

Placing DataGridView Control

Figure 14-15 DataGridView control placed on form

Added benefit: DataSet, BindingNavigator, AdapterManager, TableAdapter, and BindingSource objects automatically instantiated

Table dragged from Data Sources window to the form; DataGridView Control created

Component Tray

Customize the DataGridView Object

Use smart tag

Figure 14-16 Customizing the DataGridView control

Formatting DataGridView Cells

Figure 14-19 Formatting DataGridView cells

Customize the DataGridView Object

( continued )

BindingNavigator Control

  • One of the five objects added to the component tray at the bottom of the form when the table from the Data Sources pane is placed on form
  • Provides a standardized way to move through and process the data
  • Much functionality is automatically programmed into the tool strip - Code was also automatically generated

BindingNavigator Control

(continued )

Figure 14-20 BindingNavigator and BindingSource objects

TableAdapterManager

private void studentBindingNavigatorSaveItem_Click (object sender, EventArgs e) { this.Validate( ); this.studentBindingSource.EndEdit( ); this.tableAdapterManager.UpdateAll (this.studentDataBaseDataSet.Student); }

  • UpdateAll( ) method of a TableAdapterManager class
  • TableAdapterManager is extremely useful when an application pulls data from two or more tables - It uses the foreign-key relationships to retrieve and save data in related data tables

TableAdapters

  • Data adapter on steroids
  • TableAdapter’s Update( ) method has to have available SQL Select, Insert, Delete, and Update commands
  • Configure TableAdapter to update data
    • Select the TableAdapter object in component tray to view its properties - TableAdapter has SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand properties - Set the SQL query for the CommandText for these properties
    • Use the DataSet Designer to view and modify CommandText for these properties

Dataset Designer (continued)

Figure 14-21 Dataset Designer opened

TableAdapter object

Reviewing the TableAdapter's

Command Properties

Figure 14-22 Updating the SelectCommand

Clicking in the value box beside the UpdateCommand property reveals New

Query Builder ( continued )

  • First prompted to select the table
  • Can type the SQL statement into the SQL pane or
  • Use the Diagram pane to select columns you want to update
  • Grid pane in the center can be used to filter and enter parameterized expressions
  • Results pane can be used for testing query
    • Located at bottom of the Query Builder

Query Builder ( continued )

Figure 14-23 Identify the Table for the Update