Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Forms Navigating database with windows forms.

Similar presentations


Presentation on theme: "Windows Forms Navigating database with windows forms."— Presentation transcript:

1 Windows Forms Navigating database with windows forms.

2 VB.net application Tiered application  Provide a means to develop many presentations of the same app  Makes changes to the back end easier when it is not tied into one class

3 Tiers continued  You have three tiers Presentation (The form or front end) Business  Used to make all the calculated values in the form  Enforces the Business rules of your application Data Tier (Provides connections and manages rules (SQL) of the database)

4 The Data tier  A windows component added to your project  Like the form, a windows component is also a class.  This class will contain all the Connection, DataAdapters and DataSets that are needed for the data Tier. Each of these are considered to be private To access these objects and all methods and properties, require the use of Accessor methods/sub procedures that you must create

5 Data Tier (Continued)  Two methods are needed in the data tier 1.A function that will return a reference to the datset to the form (getDataSet()). 2.A sub procedure that will provide access to the Update method of the DataAdapter (Update()) AS a refresher  All SQL statements are managed by the DataAdapter  All Connections to the database are managed by the connection object  A local copy of the database in the DataSet

6 The Data Tier in detail

7 DataSets  DataSets hold a local copy of the database.  Any changes of the dataset have to be pushed back to the server  The Update Function in the DataAdapter takes only the rows of data that have changed and then push them onto the database.

8 DataSet Continued  Data can change on a DBMS on a network frequently  Once an update occurs, the DataSet must accept all changes that Occur in the DBMS  The AcceptChanges() function of the datset must be called after an update is made

9 Adding and Editing Form design and changing data in a database

10 Form design for Adding records  When adding or editing a record in the data set all navigation should be disabled. This prevents the user from accidentally moving the position of the record during an edit. All other buttons should be disabled  i.e. Edit and Delete buttons  Separate sub procedures should be created to do this

11 Navigation sub procedures  When a form opens All textboxes should be disabled Buttons that are not needed should also be disabled (i.e. Cancel button) This is often called enabling navigation  There are therefore two sub procedures that must be created enableNav() disableNav()

12 Example code of enbleNav() Private Sub enableNav() txtFirstNAme.Enabled = False txtLastName.Enabled = False txtAddress.Enabled = False txtCity.Enabled = False txtState.Enabled = False txtZip.Enabled = False btnNext.Enabled = True btnPrev.Enabled = True btnCancel.Enabled = False End Sub

13 Example code of disableNav() Private Sub disableNav() txtFirstNAme.Enabled = True txtLastName.Enabled = True txtAddress.Enabled = True txtCity.Enabled = True txtState.Enabled = True txtZip.Enabled = True btnPrev.Enabled = False btnNext.Enabled = False btnCancel.Enabled = True End Sub

14 Adding Records  The BindingManagerBase object in the form contains an AddNew() Sub Procedure which clears all bound textboxes Moves the position of the record to the end Auto increments all key id fields (if they are set for auto increment) This sub procedure is added to the event handler of the Add Button

15 Example Form for adding a recod

16 Adding a record continued  Buttons can also be used for two purposes  With the Add button Click once it places the form in a position to add a record Once the information is added to the text fields, the button can be clicked again to save the record (code provided to student).

17 Saving a record  There are specific steps that are taken to save a record to a database 1.Call the EndCurrentEdit() sub procedure in the BindingManagerBase object 2.Call the Update sub procedure in the DataAdapter (located in the data tier) 3.Call the AccpetChanges sub procedure in the DataSet (also located in the data tier) Taken these steps in this order will ensure that all the data will be saved to the database

18 Edit buttons follow the same design as add


Download ppt "Windows Forms Navigating database with windows forms."

Similar presentations


Ads by Google