Intro

Document Sample
Intro Powered By Docstoc
					PROG3180: MS MobiDev
Handbook
Chapter 3: SQL Server CE




         Note: The content of these slides were
         mainly from the MS Mobile Development
         Handbook, 2e
    Overview
   SQL Server CE database
   Smart Device Project Data Source
   Strongly Typed DataSets
   Data-bound GUI
   Master-Detail Forms
    SQL Server CE database
   Off-line mobile application:
       Data is stored on the device
   Additional software required
       SQL Server Compact 3.5 Service Pack 1
   Create a SQL CE database
       VS 2008 Server Explorer
            Create Table
            Create Relationship (Foreign Key)
       SQL Server Management Studio
    SQL Server CE runtime on
    WM 6.1 Professional device
   VS 2008 automatically installs at least these
    runtime components:
       .NET CF 3.5: NETCFv35.wm.armv4i.cab
       Main runtime: sqlce.ppc.wce5.armv4i.CAB
       Replication support: sqlce.repl.ppc.wce5.armv4i.CAB
   You can install the .cab files on physical devices
       Copy the files and open in File Explorer
   These files are also in:
       K:\ITPROGRAMS\CPA\Year3\MobiProg\
        AssignmentCABs\msCABs
       VS 2008 Server Explorer
        SQL Server CE




   Refer to WM6 RampUp HOL5 for
    more details
    SqlCeExceptions
   SQL Server CE runtime raises a SqlCeException
    when an operation fails
       Has Errors property of type SqlCeErrorCollection
       Contains at least one SqlCeError instance
       SqlCeError object exposes more details
   Sample code in DisplaySQLCEErrors() method
    of MainForm.cs displays the full contents of a
    SqlCeException in a message box
   SQLMasterDetail.zip can be found in
       K:\ITPROGRAMS\CPA\Year3\MobiProg\msdevSamples\
Smart Device Project
Data Source
   Data | Show Data Sources
       Add New Data Source link
   Default Custom Tool:
       MSDataSetGenerator
   DataSet Designer
       Edit generated commands



   Note: To secure connection
    strings, see Chapter 10.
    Strongly Typed DataSet
   An object that inherits from
    System.Data.DataSet but exposes additional
    properties that represent the table schema to
    which it is strongly typed
   E.g, myDataSet contains two tables that store data
    from the Orders and OrderDetails tables
      Use intuitive names such as myDataSet.Orders

       and myDataSet.OrderDetails
      Instead of myDataSet.Tables[0] and

       myDataSet.Tables[1]
    DataSet vs.
    SqlCeResultSet
   Both for a data-bound GUI or as a means of
    manipulating data in a database
   DataSet object is functionally very rich
       DataTable , DataColumn, DataRow
      can impose constraints on data such as FK
      Benefit: rapid prototyping (advanced features);

       multiple table; for faster devices
   SqlCeResultSet does not store data
      read or update data directly in the database

      Benefit: increase performance for slower devices
          Using DataSet to store data
   BindingSource Control
        Sits between the control and the data source (DataSet)
        Easy to build data-bound UIs
        Available in SmartTag of DataGrid bound to a DataSet
         data source




    Note: Use DataSet for your assignment.
        TableAdapter
   Opens the DB connection before they execute
    and close it at the end.
       No need to call DB Open/Close methods
   TableAdapter.Fill()
      To populate the DataSet with the data from
       the table
            E.g., productTableAdapter.Fill(productsDataSet.Product)
   TableAdapter.Update()
      To update the database table from the
       DataSet
            E.g.,
             productTableAdapter.Update(productsDataSet.Product);
    Data-Bound GUI
   Generating Data Forms
       Display records in a DataGrid, add new
        records, and to view or edit existing records
   Options to build UI
       DataGrid, Details, or None
   BindingSource control
       simplifies binding controls on a form to data
       attach the BindingSource component to your
        data source and form controls
       Call methods of the BindingSource
        component.
    BindingSource control
   Use BindingSource control
       Simplifies complex Windows Forms binding
            Provides IBindingList services for non-IBindingLists
       More flexible
            Supports type-based binding
            Provides centralized control for binding operations
            Simplifies currency management
   DataSet, BindingSource, DataGrid Example
       productDataGrid
            DataSource property is set to productBindingSource.
       productBindingSource
            DataSource property is set to productsDataSet, and the
             DataMember property is set to the Product table
    BindingSource Methods
   Add record: AddNew()
       E.g., productBindingSource.AddNew();
       To initialize columns in the new record, set the default value
            E.g., this.productsDataSet.Product.SizeColumn.DefaultValue = "M";
   Navigation:
       MoveFirst(), MoveNext(), MovePrevious(),
        MoveLast()
       Updates the BindingSource.Position property
   Accepting and Canceling Updates
       EndEdit(): save the updates
            put a try..catch around calls to EndEdit to catch data
             validation errors
       CancelEdit(): discard any updates
    Field data-binding options
   Set options before
    generating data forms
   Data-binding control
    options:
       None
       Label, TextBox
       ListBox, ComboBox
       NumericUpDown,
       DateTimePicker, etc.
        Master-Detail Forms
   Quick UI with DataSet
   Drag-and-Drop to form
       ProductCategory
       Child Product

Result:
   product_productCategory_FKBindingSource
       DataSource :productCategoryBindingSource
       DataMember : Product_ProductCategory_FK
          foreign key between the ProductCategory and
           Product tables.
        Master-Detail Sample
   Generate Data Form for Child Product DataGrid to
    allow edit




   SQLMasterDetail.zip
    can be found in
       K:\ITPROGRAMS\CPA\Year3\
        MobiProg\msdevSamples\

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:10
posted:9/18/2011
language:English
pages:17