Windows phone Local Database (SQLCE): 13, update data (translation)

Source: Internet
Author: User

This is the 13th article in the "Windows Phone Mango Local Database (SQLCE)" series. To get you started using the database in Windows Phone Mango, this series of short film articles will cover all the knowledge you need to know. I'll talk about how to update the data in the Windows Phone Mango Local database.

updating data to a database is a three-step process. First, query the object to be updated, then change the data, and finally call the SubmitChanges method to save these changes to the database. Note : If you bind an object in DataContext to a control on a page, the data is automatically updated based on the user's interaction. Then, in the desired time, only one step is required to call the SubmitChanges method. Note : The data will not be updated until the SubmitChanges method is called. Reference: You can look at the MSDN documentation http://msdn.microsoft.com/zh-cn/library/hh202861 (v=vs.92). aspx1. How to update databefore we start, let's say we have the database structure of the following two tables: Country and City

DataContext as follows

1PublicClassCountrydatacontext:datacontext2{3Public Countrydatacontext (StringconnectionString)4:Base(connectionString)5{6}78Public table<country>Countries9{10Get11{12ReturnThis. Gettable<country>();13 }14 }15 16 public Table <city> Cities17  {18 get19  {20 return this. Gettable<city> (); }22 }23}                 
in the following code example, I will demonstrate several procedures:1. Create DataContext2, find the target to be updated "city"3, update city's name Madrid4. Call the SubmitChanges method to save the changes.
1PrivatevoidUpdatecity ()2{3using (countrydatacontext context =NewCountrydatacontext (ConnectionString))4{5//Find a city to update6 iqueryable<city> cityquery =From cIn context. Citieswhere c.name = ="Barcelona"Select C;  Cityquery.firstordefault ();  8  9 // update the city by Changing its name10 citytoupdate.name =  "madrid "; One 12 // save changes to The Database13  context. SubmitChanges (); 14 }15}     

This article I talked about updating data on the Windows Phone Mango Local database. Keep your eye on the next article.

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.