Page 94 - DCAP312_WEB_TECHNOLOGIES_II
P. 94

Web Technologies-II



                   Notes
                                                The following code accesses the CustomerID column in the first row of the
                                                Customers table
                                                string str;
                                                str=dset.Customers[0].CustomerID;

                                 Untyped Dataset
                                 Untyped dataset is not defined by a schema, instead, you have to add tables, columns, and
                                 other elements to it yourself, either by setting properties at design time or by adding them
                                 at run time. For example : scenario: if you don’t know in advance what the stucture of your
                                 program is that interacting with a component that returns a dataset. the equivalent code above
                                 for Untyped dataset is:
                                           string str;
                                           str=(string)dset.Tables[ “Customers”].Row[0].[ “CustomerID”];
                                 A dataset is a container; therefore, you have to fill it with data.
                                 You can populate a dataset in a variety of ways;

                                    •   By using Fill method.
                                    •   By creating DataRow objects and adding them to the table’s Rows collection(only at run
                                      time).
                                    •   Read an XML document or stream into the dataset.
                                    •  Merge (copy) the contents of another dataset.

                                 5.1.3 Display Data in a DataGrid
                                 The Windows Forms DataGrid control displays data in a sequence of rows and columns. The
                                 Windows Forms DataGrid control provides a user interface to ADO.NET datasets. It displays
                                 tabular data and allows for updates to the data source. When you set DataGrid control to a
                                 suitable data source, the control will be automatically populated, creating columns and rows
                                 based on the shape of the data. You can use the DataGrid control for displaying either a single
                                 table or the hierarchical relationships between a set of tables. If you want to work with the
                                 DataGrid control, DataGrid should be bound to a data source by using
                                    •  the DataSource and

                                    •  DataMember properties at design time
                                       or
                                    •  the SetDataBinding method at run time.

                                 Here is the binding to the DataGrid control with DataSet used in this project.
                                           this . dataGrid1 . DataSource = datc . dSet . Tables[ “PersonTable”];
                                 You can only show one table in the DataGrid at a time. If you define a parent-child relationship
                                 between  tables,  you can navigate  between  the  related tables  to select the  table  you want  to
                                 display in DataGrid control.

                                                dset.Relations.Add( “CustomerOrders”,
                                                dset.Tables[ “customers”].Columns[ “CustomerID”],
                                                dset.Tables[ “orders”].Columns[ “CustomerID”]);




        88                                LOVELY PROFESSIONAL UNIVERSITY
   89   90   91   92   93   94   95   96   97   98   99