Access SQL Server 5.0 on Windows Mobile 3.5 (1)

Source: Internet
Author: User
For personal reasons, I haven't written a blog for a long time. Changes in mobile development can only be described as changing. Wm7 is coming soon, and SQL Server ce has reached 3.5, which cannot keep up with the pace.

This articleArticleHow to Use wm5.0 to develop SQL Server Ce-based applicationsProgramRight.

The following describes the basics of SQL Server Ce:
SQL Server 2005 compact edition (abbreviated as SQL Server CE) is a streamlined database product launched by Microsoft for embedding data in mobile application devices, windows Mobile developers can use SQL Server ce to develop applications that extend data management capabilities to Windows Mobile devices. SQL Server ce not only provides complete SQL syntax, including internal join, external join and subquery, but also supports data synchronization technology. Note that, apart from running SQL Server 2005 compact edition on Windows Mobile devices as a mobile database, it also supports data storage on PCs, provides data support for desktop applications. However, it seems that views and stored procedures are not supported.

The SQL Server ce database engine also provides two important technologies, namely remote data access and merge replication. Both methods are used to synchronize data with the remote database, so that we can easily load the information in the remote database to the SQL Server ce database on the device side, in addition, We can insert, delete, update, and other modifications to the SQL Server ce database offline. Finally, we can send the modified data back to the remote database, ensures data synchronization between the device and the server. (Further descriptions will be made in subsequent articles)

Here is an overview of the basics. Let's start with the demo and try SQL Server ce.
Development Environment: vs2008
Development language: C #
Database: SQL Server ce3.5
Vs2008 is used as the development environment. In the future, the development environment of vs2005 will be used.

Open vs2008, select smart device, and select. Net Framework 2.0 in the upper right corner to create an Application Based on. NET framework2.0.

Select the platform type (PPC/Smartphone). Here I select PPC. Note that cf2.0 or cf3.5 can also be selected in the options below, and 2.0 is selected here.

After the project is created, a simulator device will appear when you create a form program.

Add a database and add a database on the project interface.

At this time, you will find how the suffix of the database file is changed to. SDF. Then, create a corresponding dataset for rapid development. (This article mainly describes some functions, which are not referenced in actual project development)
After creating a table, drag the table to dataset. vs automatically generates the corresponding adapt and strong dataset.
Then, drag a DataGrid in form and set the dock of the DataGrid to fill. When developing WM, it is best to set the dock, because the control will be automatically adjusted as the device changes, WM can be used side by side.

With the data container, You need to bind data.
First, set the DataGrid. Because the DataGrid version is CF, many attributes and methods are much less than those on winform.
Add a tabstyle to bind a datatable. Set generatemember to false and specify mappingname (table name ).

Add a column in gridcolumnstyles. I will add two columns: datagridtextcolumn, set generatememember to false, and specify mappingname (column name ).

In the form_load event, use adapt to fill a table and bind it to the DataGrid.
If the mappingname of tablestyle and columnstyle is not set before, some columns will be added when it is bound here.

This is the effect you don't want.

This is the desired effect.

The DataGrid cannot set the visible of a column and does not have this attribute. This method can only be used to shield some columns.

The DataGrid cannot be edited directly. How can we edit it? The method is as follows:
Create a new form and pass the selected row information as a parameter to the edit form. After the form is edited, return it to obtain the data.

The simple database access application is complete.CodeAs follows:

Code
1 Using System;
2
3 Using System. Collections. Generic;
4 Using System. componentmodel;
5 Using System. Data;
6 Using System. drawing;
7 Using System. text;
8 Using System. Windows. forms;
9
10 Namespace Smartdeviceproject1
11 {
12 Public   Partial   Class Form1: Form
13 {
14 Private Appdatabase1dataset. sys_userdatatable table;
15 Appdatabase1datasettableadapters. sys_usertableadapter adapt;
16
17 Public Form1 ()
18 {
19Initializecomponent ();
20}
21
22 Private   Void Menuitem4_click ( Object Sender, eventargs E)
23 {
24Application. Exit ();
25}
26
27 Private   Void Menuitem3_click ( Object Sender, eventargs E)
28 {
29 Adapt =   New Smartdeviceproject1.appdatabase1datasettableadapters. sys_usertableadapter ();
30 Adapt. Fill (table );
31 This . Datagrid1.datasource = Table;
32 }
33
34 Private   Void Form1_load ( Object Sender, eventargs E)
35 {
36Table= NewAppdatabase1dataset. sys_userdatatable ();
37}
38
39 Private   Void Menuitem5_click ( Object Sender, eventargs E)
40 {
41 If (Adapt =   Null )
42 Adapt =   New Smartdeviceproject1.appdatabase1datasettableadapters. sys_usertableadapter ();
43
44 MessageBox. Show ( " Effect rows are "   + Adapt. Update (table). tostring ());
45 }
46
47 Private   Void Menuitem6_click ( Object Sender, eventargs E)
48 {
49 // Form2 is used to edit a form. After passing in a value, modify it in the form, then retrieve the data and write it into the able.
50 Form2 form =   New Form2 ();
51 Form. user_id = Table [ This . Maid. rownumber]. user_id;
52 Form. user_name = Table [ This . Maid. rownumber]. user_name;
53 Form. Mail = Table [ This . Maid. rownumber]. mail;
54 Form. showdialog ();
55
56 If (Form. issave)
57 {
58 Table [ This . Maid. rownumber]. user_id = Form. user_id;
59 Table [ This . Maid. rownumber]. user_name = Form. user_name;
60 Table [ This . Maid. rownumber]. Mail = Form. mail;
61 }
62 }
63 }
64 }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.