Development of SqlCe Database under WinCE (II.)

Source: Internet
Author: User

The last time you write a method that uses data binding to test the local sqlce database, this time using the Access SQL Server method to access SqlCe, you will find that they are so similar ...

Reference: http://www.cnblogs.com/rainman/archive/2012/03/13/2393975.html

At the end of this article, you can download all the code for this test. Of course, I prefer this place as an exchange platform, able to learn from each other, if you have any other ideas you wish you could tell me.

Note: Development environment VS2008 Development language: C #

1. Create the WinForm form program under wince:

The specific process is no longer detailed, can refer to the previous blog post, I have done here a simple data deletion and modification of the example.

Note: You will need to add a reference to the SqlServerCe after the creation is complete:

Path: C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\devices\system.data.sqlserverce.dll

Add Reference: Using System.Data.SqlServerCe

Figure 1 Adding a reference to SqlServerCe

For the main form, contains

6 buttons, respectively: Full display, partial display, add, delete, modify and exit;

1 DataGrid: for data display.

Figure 2 Main form

2. Show All

Figure 3 Adding the displayed database file

Figure 4 Show All

1 stringSTRADDR ="";2 3OpenFileDialog OFD =NewOpenFileDialog ();4   if(OFD. ShowDialog () = =DialogResult.OK)5   {6STRADDR =OFD. FileName;7   }8   stringConstr ="Data source="+ straddr +";";9SqlCeConnection conn =NewSqlCeConnection (constr);Ten   Conn. Open (); One  A   stringCmdtxt ="SELECT * from DBtest"; -SqlCeDataAdapter ADAP =NewSqlCeDataAdapter (Cmdtxt, conn); -DataSet ds =NewDataSet (); the   ADAP. Fill (DS); -  -DataGrid1.DataSource = ds. tables[0]. DefaultView;

3. Partial display

For the partial display, this time only reads the name and the sex two column, the careful words you will notice here is "the name" "The gender" instead of all displays "the name" "The Sex"

Figure 5 Section shows

1  stringSTRADDR ="";2 3OpenFileDialog OFD =NewOpenFileDialog ();4   if(OFD. ShowDialog () = =DialogResult.OK)5   {6STRADDR =OFD. FileName;7   }8   stringConstr ="Data source="+ straddr +";";9SqlCeConnection conn =NewSqlCeConnection (constr);Ten   Conn. Open (); One  A  stringCmdtxt ="select name as name, sex as gender from DBtest"; -SqlCeDataAdapter ADAP =NewSqlCeDataAdapter (Cmdtxt, conn); -DataSet ds =NewDataSet (); the   ADAP. Fill (DS); -  -DataGrid1.DataSource = ds. tables[0]. DefaultView;

4. Delete

Remove the item "name" as "Zhao" and reopen the partial display (no way, add delete does not do input control, cannot select or fill in the information, take a fixed item to do an example)

Figure 6 Deleting

1   stringSTRADDR ="";2OpenFileDialog OFD =NewOpenFileDialog ();3   if(OFD. ShowDialog () = =DialogResult.OK)4   {5STRADDR =OFD. FileName;6   }7   stringConstr ="Data source="+ straddr +";";8SqlCeConnection conn =NewSqlCeConnection (constr);9 Conn. Open ();Ten  OneSqlCeCommand mycommand =NewSqlCeCommand (); AmyCommand.CommandType =CommandType.Text; -   //mycommand.commandtext = "Select Select name as name, sex as gender from DBtest"; -myCommand.CommandText ="Delete from DBtest where name= ' Zhao '"; themycommand. Connection =Conn; -  - mycommand. ExecuteNonQuery (); -Conn. Close ();

5. Increase

Note: This operation needs to be done after deletion, otherwise the program will error because of the same record (this is just an example, don't try to be too perfect ==! )

Figure 7 Add

1   stringSTRADDR ="";2OpenFileDialog OFD =NewOpenFileDialog ();3   if(OFD. ShowDialog () = =DialogResult.OK)4   {5STRADDR =OFD. FileName;6   }7   stringConstr ="Data source="+ straddr +";";8SqlCeConnection conn =NewSqlCeConnection (constr);9 Conn. Open ();Ten  OneSqlCeCommand mycommand =NewSqlCeCommand (); AmyCommand.CommandType =CommandType.Text; -   //mycommand.commandtext = "Select Select name as name, sex as gender from DBtest"; -myCommand.CommandText ="INSERT INTO DBtest (Name,sex,tel) VALUES (' Zhao ', ' Mans ', ' 111111111 ')"; themycommand. Connection =Conn; -  - mycommand. ExecuteNonQuery (); -Conn. Close ();

6. Modifications

Change the "Zhao" record "tel" to "2222222222" (note, originally 1111111111, the previous one has just been added)

Figure 8 Modifying

7. Write in the last words

I am not a computer origin, the upper machine development and database is purely self-study, but still hope to be able to communicate with friends. I also have a lot of not, but I will I will, or think can be a good solution to a problem of the way out and communicate with you, hoping to use the platform blog, to make a lot of like-minded friends!!!!!

8.

Code:

http://download.csdn.net/detail/u010312811/8398555

Download the points a bit high, it is csdn too pit, I was also the other netizens put the points have been pit. Do not want to spend points can leave the mailbox, I sent the code past, sorry ha

Development of SqlCe Database under WinCE (II.)

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.