开发者

using local database to save a variable in windows phone 7

How do I use local database in windows phon开发者_运维知识库e 7 to save just a value, then retrieve that value every time the app is loaded (opened)?


If all you want to do is store a value for retrieval, then I would recommend using IsolatedStorage, particularly the ApplicationSettings class.

An example of it's usage:

using System.IO.IsolatedStorage;

//storing value
int someValue = 10;
IsolatedStorageSettings.ApplicationSettings.Add("MyKey",someValue);

//write or update value
IsolatedStorageSettings.ApplicationSettings["MyKey"] = someValue;

//write to disk
IsolatedStorageSettings.ApplicationSettings.Save();


//reading value
if(IsolatedStorageSettings.ApplicationSettings.Contains("MyKey"))
{
   int readValue = (int) IsolatedStorageSettings.ApplicationSettings["MyKey"];
}   

Mango now offers MSSqlCE support, but for a set of values, it's overkill. A database is more appropriate if you need to store relational data, as opposed to persisting user/application settings.

While IsolatedStorage is nice, it can be expensive to read and write to. Avoid reading from IsolatedStorage from your UI thread, which will cause your app to appear to be unresponsive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜