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