. Net CF development cainiao notes (PDA application development)

Source: Internet
Author: User

I. SQL mobile terminal database operations

1. Create an SDF Database
After vs2005 is installed, the SQL ce name is SQL mobile. Create a mobile application and add an SQL mobile database to the project, then, you can directly design the structure of the new database and add data in vs2005. When using the simulator to debug a program, if you want to retain the database data on the simulator, you can remove the. SDF file in the vs2005 project, so that each debugging will not overwrite the database file on the simulator.

2. Database Connection
Read the msdn documentation clearly, but note that the msdn connection strings are mostly written as Conn. connectionstring = "Data Source = 'cookbook. SDF '";
The database file does not contain a path. It cannot be written on a mobile device. It seems that the relative path cannot be used and the absolute path must be used,
Conn. connectionstring = "Data Source = '" + path. getdirectoryname (system. reflection. assembly. getexecutingassembly (). getname (). codebase) + @ "\ cookbook. SDF '";

In this way, you can succeed.

3. Data Operations
I wrote it clearly on msdn.

Sqlceconnection conn = This. getconn ();
Conn. open ();
String xiid = This. cbox. selecteditem. tostring ();
Xiid = xiid. substring (0, 1 );

Sqlcecommand COM = new sqlcecommand ();
Com. Connection = conn;
Com. commandtext = "insert into cookmain (name, descr, xiid) values ('" + this. cookname. Text. Trim ()
+ "','" + This. content. Text. Trim () + "'," + xiid + ")";

If (COM. executenonquery ()> 0)
MessageBox. Show ("saved successfully! ");

MessageBox. Show ("failed to save, please add again ");
Conn. Close ();

This is a simple insert operation.

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.