VB .net tutorial - 6

download VB .net tutorial - 6

of 33

Transcript of VB .net tutorial - 6

  • 8/14/2019 VB .net tutorial - 6

    1/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 1 of 33

    Objectives

    In this lesson, you will learn to:

    Bind and display data in a Windows Form

    Filter data

    Sort data

    Display data from multiple tables in a single Windows Form

  • 8/14/2019 VB .net tutorial - 6

    2/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 2 of 33

    Problem Statement 6.D.1

    An application needs to be created that allows the MarketingManager of Diaz Telecommunications to view the customerdetails in a customized format since the new product detailsare to be sent to all the customers. The customer details arelocated in the database at a remote call center.

  • 8/14/2019 VB .net tutorial - 6

    3/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 3 of 33

    Task List

    Identify the data that needs to be displayed.

    Identify the mechanism to display data in a customized

    format.

    Design a Windows Form to display the data.

    Connect to the database.

    Bind the data to a Windows Form control.

    View the data.

  • 8/14/2019 VB .net tutorial - 6

    4/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 4 of 33

    Task 1: Identify the data that needs to be displayed.

    Result:

    As per the given problem statement, the data to be

    displayed is as follows:

    CustID

    FName

    LName

    Address

    Phone

    email

  • 8/14/2019 VB .net tutorial - 6

    5/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 5 of 33

    Task 2: Identify the mechanism to display data in acustomized format.

    Data binding is the process of binding the retrieved data to a

    control on a Windows Form to be displayed in acustomized format.

    Data binding is of two types:

    Simple Data Binding

    Complex Data Binding

    Result:

    For the given problem statement, you will use complex databinding to display the data.

  • 8/14/2019 VB .net tutorial - 6

    6/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 6 of 33

    Just a Minute

    What is the difference between simple data binding andcomplex data binding? What are the controls used in eachtype of binding?

  • 8/14/2019 VB .net tutorial - 6

    7/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 7 of 33

    Task 3: Design a Windows Form to display the data.

    Task 4: Connect to the database.

    Task 5: Bind the data to a Windows Form control.

    Task 6: View the data.

  • 8/14/2019 VB .net tutorial - 6

    8/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 8 of 33

    Problem Statement 6.D.2

    An application needs to be created that allows the MarketingManager of Diaz Telecommunications to view customerdetails since the new product details are to be sent to all thecustomers. In addition, the Marketing Manager should be ableto navigate through the customer details. The customer detailsare located in the database at a remote call center.

  • 8/14/2019 VB .net tutorial - 6

    9/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 9 of 33

    Task List

    Identify the data that needs to be displayed.

    Identify the mechanism to display data in a customized

    format.

    Identify the mechanism to navigate through the data.

    Design a Windows Form to display the data.

    Connect to the database.

    Write the code to navigate through the data.

    Bind the data to a Windows Form control.

    View the data.

  • 8/14/2019 VB .net tutorial - 6

    10/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 10 of 33

    Task 1: Identify the data that needs to be displayed.

    Result:

    As per the given problem statement, the data to be

    displayed is as follows:

    CustID

    Fname

    Lname

    Address

    Phone

    email

  • 8/14/2019 VB .net tutorial - 6

    11/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 11 of 33

    Task 2: Identify the mechanism to data in acustomized format.

    Result:

    For the given problem statement, you will use simple databinding to bind and display the data.

  • 8/14/2019 VB .net tutorial - 6

    12/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 12 of 33

    Task 3: Identify the mechanism to navigate throughthe data.

    The CurrencyManager class

    Exists for every data source that is bound to a WindowsForm.

    Object handles the binding to the data source bykeeping a pointer to the current item in the record list.

    Is derived from the BindingManagerBase class.

    A BindingContext object, which is a Windows Formobject, is used to keep track of the existing

    CurrencyManager objects in a form.

  • 8/14/2019 VB .net tutorial - 6

    13/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 13 of 33

    Task 3: Identify the mechanism to navigate throughthe data. (Contd.)

    Relationship between the BindingContext class,CurrencyManager class, and Windows Form:

    Windows FormControl 1Control 2Control 3

    BindingContextobject

    CurrencyManager 1

    CurrencyManager 1

    CurrencyManager 1

    DATA SOURCE 1

    DATA SOURCE 1

    DATA SOURCE 1

  • 8/14/2019 VB .net tutorial - 6

    14/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 14 of 33

    Task 3: Identify the mechanism to navigate throughthe data. (Contd.)

    Result:

    You will use the BindingManagerBase class and theBindingContext() method to navigate through therecords.

    Task 4: Design a Windows Form to display the data.

    Task 5: Connect to the database.

    Task 6: Write the code to navigate through the data.

    Task 7: Bind the data to a Windows Form control.

    Task 8: View the data.

  • 8/14/2019 VB .net tutorial - 6

    15/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 15 of 33

    Problem Statement 6.D.3

    An application needs to be created for the Marketing Managerof Diaz Telecommunications to view the order details for aspecific invoice to verify the monthly sales report.

  • 8/14/2019 VB .net tutorial - 6

    16/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 16 of 33

    Task List

    Identify the data that needs to be displayed.

    Identify the method to filter and sort the data.

    Identify the method to navigate through the data.

    Design a Windows Form to display the data.

    Connect to the database, and filter and sort the data.

    Bind the data to a Windows Form control.

    View the data.

  • 8/14/2019 VB .net tutorial - 6

    17/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 17 of 33

    Task 1: Identify the data that needs to be displayed.

    Result:

    As per the given problem statement, the data to be

    displayed is as follows: Inv

    Date

    CustID

    ProdID

    Cost

    Advance

  • 8/14/2019 VB .net tutorial - 6

    18/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 18 of 33

    Task 2: Identify the method to filter and sort the data.

    There are two methods to display filtered data:

    Parameterized queries

    Filter data based on the criterion entered by a userat run time.

    Are created while configuring data adapters.

    Filtering a dataset

    After the data is retrieved in a dataset, the data canbe filtered by:

    Using the Select() methodFiltering a data view

  • 8/14/2019 VB .net tutorial - 6

    19/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 19 of 33

    Task 2: Identify the method to filter and sort the data.(Contd.)

    The Select() method

    Used to filter data without changing the order of therecords in the table based on the parameter passed.

  • 8/14/2019 VB .net tutorial - 6

    20/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 20 of 33

    Just a Minute

    The records of customers having monthly income of $4200needs to be displayed in ascending order of their names fromthe table Employees. Write the code to retrieve filtered recordsand store the retrieved records.

  • 8/14/2019 VB .net tutorial - 6

    21/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 21 of 33

    Task 2: Identify the method to filter and sort the data.(Contd.)

    Filtering a data view

    A DataView object creates a fixed customized view ofa given DataTable object.

    By default, every table in a dataset has a data viewattached to it.

    Multiple DataView objects can also be explicitlycreated for displaying different views of the sameunderlying data.

  • 8/14/2019 VB .net tutorial - 6

    22/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 22 of 33

    Task 2: Identify the method to filter and sort the data.(Contd.)

    Some commonly used properties of the DataViewobject:

    Table

    Sort

    RowFilterRowStateFilter

    AllowNew, AllowDelete, AllowEdit

  • 8/14/2019 VB .net tutorial - 6

    23/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 23 of 33

    Task 2: Identify the method to filter and sort the data.(Contd.)

    Result:

    You will use a parameterized query to filter and sort thedata, as it requires you to write minimum code.

  • 8/14/2019 VB .net tutorial - 6

    24/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 24 of 33

    Just a Minute

    The name, date of joining, and department of the employeeswith salary greater than $2000 need to be retrieved anddisplayed in a DataGrid control. Write the code to filter the

    data and display the filtered data.

  • 8/14/2019 VB .net tutorial - 6

    25/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 25 of 33

    Task 3: Identify the method to navigate through thedata.

    Result:

    You will use the BindingManagerBase class and theBindingContext() method to navigate through the data.

    Task 4: Design a Windows Form to display the data.

    Task 5: Connect to the database, and filter and sortthe data.

    Task 6: Bind the data to a Windows Form control.

    Task 7: View the data.

  • 8/14/2019 VB .net tutorial - 6

    26/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 26 of 33

    Problem Statement 6.D.4

    An application needs to be created for the DiazTelecommunications Marketing Manager to view customerdetails, such as the name and address, and order details for a

    specific customer for analyzing customer feedbacks. Thecustomer details and the order details are present in separatetables.

  • 8/14/2019 VB .net tutorial - 6

    27/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 27 of 33

    Task List

    Identify the data that needs to be displayed.

    Identify the mechanism to display data from multiple tables

    in a single Windows Form.Design a Windows Form to display the data.

    Connect to the database.

    Create a relationship between the tables.

    Bind the data to the Windows Form controls.

    View the data from multiple tables in a single Windows

    Form.

  • 8/14/2019 VB .net tutorial - 6

    28/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 28 of 33

    Task 1: Identify the data that needs to be displayed.

    Result:

    As per the given problem statement, the data to be

    displayed is as follows: FName

    Address

    ProdID

    Inv

    Date

    CustID

  • 8/14/2019 VB .net tutorial - 6

    29/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 29 of 33

    Task 2: Identify the mechanism to display data frommultiple tables in a single Windows Form.

    Tables are stored in a dataset as discrete entities but arelationship can be created between the stored tables todisplay data from the related tables.

    The column that is common in both the tables is used tocreate the relationship.

    Result:

    You will create a relationship between CustomerTrackingand CustOrder tables to display the data from both thetables.

  • 8/14/2019 VB .net tutorial - 6

    30/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 30 of 33

    Task 3: Design a Windows Form to display the data.

    Task 4: Connect to the database.

    Task 5: Create a relationship between the tables.

    Task 6: Bind the data to the Windows Form controls.

    Task 7: View the data.

  • 8/14/2019 VB .net tutorial - 6

    31/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 31 of 33

    Summary

    In this lesson, you learned that:

    After the data is retrieved from the database, it has to be

    bound to a Windows Form control to be displayed in acustomized format.

    Data binding is of two types:

    Simple data binding

    Complex data binding

    Using parameterized queries, the data can be filteredbased on the criterion entered by a user.

  • 8/14/2019 VB .net tutorial - 6

    32/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 32 of 33

    Summary (Contd.)

    After the data is retrieved in a dataset, you can filter thedata stored in the dataset by:

    Using the Select() method

    Using DataView objects

    A DataView object allows a fixed customized view of agiven DataTable object.

    A data view manager is a collection of data viewsand is useful while working with related tables.

  • 8/14/2019 VB .net tutorial - 6

    33/33

    Accessing and Manipulating Data

    NIIT Accessing and Manipulating Data/Lesson 6/Slide 33 of 33

    Summary (Contd.)

    A CurrencyManager object handles the binding to thedata source by keeping a pointer to the current item in therecord list.

    A BindingContext object is used to keep track of theexisting CurrencyManager objects on a form.

    Tables are stored in a dataset as discrete entities, but a

    relationship can be created between the stored tables sothat the dataset displays data from the related tables.