Go to Windows Mobile 5.0 to access SQL Server 3.5 (1)

Source: Internet
Author: User

Http://www.cnblogs.com/appleseeker/archive/2008/01/25/1053269.html

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 article begins with how to use WM5.0 to develop SQL Server CE-based applications.

The following describes the basics of SQL Server CE:
SQL Server 2005 Compact Edition (abbreviated as SQL ServerCE) is a streamlined database product launched by Microsoft for embedding data in mobile application devices, windows Mobile developers can use SQL ServerCE to develop applications that extend data management capabilities to Windows Mobile devices. SQL ServerCE 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 ServerCE 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, you can insert, delete, update, and other modifications to the SQL ServerCE database offline. Then, you 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. The Code is as follows:

Code

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.