Windows Phone local database (sqlce): 13. Update Data)

Source: Internet
Author: User

A newbie recently wants to learn about the Windows Phone database and find some short tutorials. Because it is in English, it is translated by the way. The English level is not good. It is estimated that there are many mistakes in the text. If you have any children's shoes that are unfortunately read, please keep in doubt about the translation quality and give me more advice.

This is the original article address: Ghost. This is the first article in the "Windows Phone mango local database (sqlce)" series. To get you started using databases in Windows Phone mango, this series of short clips will cover all the things you need to know. I will talk about how to update data in the Windows Phone mango local database.

Updating data to the database is a three-step process. First, query the object to be updated, change the data, and finally call the submitchanges method to save the changes to the database. Note: If you bind an object in datacontext to a control on the page, data is automatically updated based on user interaction. Then, the submitchanges method is called as long as one step is required in the expected time. Note: The data will not be updated until the submitchanges method is called. Reference: You can see the msdn document http://msdn.microsoft.com/zh-cn/library/hh202861 (V = vs.92). aspx 1. How to update data before starting, suppose we have the database structure of the following two tables: country and city

Datacontext is as follows:

 1 public class CountryDataContext : DataContext 2  { 3      public CountryDataContext(string connectionString) 4          : base(connectionString) 5      { 6      } 7      8      public Table<Country> Countries 9      {10          get11          {12              return this.GetTable<Country>();13          }14      }15     16      public Table<City> Cities17      {18          get19          {20              return this.GetTable<City>();21          }22      }23  }
In the following code example, I will demonstrate several processes: 1. Create datacontext2, find the target "city" to be updated 3. Update the city name madrid4, and call the submitchanges method to save the changes.
 1 private void UpdateCity() 2  { 3      using (CountryDataContext context = new CountryDataContext(ConnectionString)) 4      { 5          // find a city to update 6          IQueryable<City> cityQuery = from c in context.Cities where c.Name == "Barcelona" select c; 7          City cityToUpdate = cityQuery.FirstOrDefault(); 8             9          // update the city by changing its name10          cityToUpdate.Name = "Madrid";11    12          // save changes to the database13          context.SubmitChanges();14      }15  }

This article describes how to update data in the Windows Phone mango local database. Continue to pay attention to the following articles.

 


This is the original address: http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--How-to-Update-data

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.