Page 95 - DCAP312_WEB_TECHNOLOGIES_II
P. 95

Unit 5: Database Access



                           //here you can use one of the following                                Notes
                           this.dataGrid1.DataSource=dset.Tables[ “customers”];
                           OR
                           this.dataGrid1.SetDataBinding(dset, “customers”);
                           customers: Parent table
                           orders: Child table
            CustomerID  in Orders is a foreign key referring to CustomerID primary key in Customers
            table.
               •  If you update the data in the bound DataSet through any mechanism, the DataGrid control
                 reflects the changes. You can update the data in the DataSet through the DataGrid control,
                 if the data grid and its table styles and column styles have the ReadOnly property set to
                 false.
            There are four most typical valid data sources for the DataGrid:
               •  DataTable class

               •  DataView class
               •  DataSet class
               •  DataViewManager class

            5.1.4. DataBindings for Textboxes
            DataBinding is the ability to bind some elements of a data basis with some graphical elements
            of a submission. The data in Windows Form is spring by calling DataBindings. Windows Forms
            allow you to bind easily to almost any structure that contains data. Windows Forms Controls
            support two types of data binding:
               1.  Simple Data Binding
               2.  Complex Data Binding

            Simple Data Binding allows you to display a single data element, such as a column value from a
            dataset table, in a control. You can simple-bind any property of a control to a data value. Simple
            Data Binding can be performed either at design time using DataBindings property of a control
            OR dynamically at run time. This is the type of binding typical for controls such as a TextBox
            control or Label control that displays typically only a single value.

                           Simple DataBinding for TextBox “textBox1”
                           textBox1.DataBindings.Add( “Text”, dataset, “studentTable.studentID”);
                           The control  “textBox1”  is  bound  to the  “studentID”  column of a  table
                           “studentTable” on the DataSet(dataset) through the BindingContext object.
                           Complex data binding is the ability of a control to bind to more than one data
                           element, typically more than one record in a database, or to more than one of
                           any other type of bindable data element. DataGrid, ListBox and ErrorProvider
                           controls support Complex data binding.
                           Here is the method used in this project to bind all TextBoxes:
                           private void fnGetDataBindingForTextBoxes()
                           {
                           this.textboxFirstname.DataBindings  .Add(  “Text”,  datc.dSet.Tables[
                           “PersonTable”], “FirstName”);


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