关于app的数据保存

我想做一个Android app,就是记录一个人每天吸烟几次,吸烟的时间,数据我现在可以保存在本地SQL,我需要怎样保存在服务器呢?需要先租用一个服务器吗?一个服务器怎么租的?您知道吗?只是存一些数据,大概二百多人的,我是个大学生,做社会调查。谢谢~

在开发过程中,我们需要将某些数据保存下来,比如一些设置信息以及一些用户主动去保存的数据。待用户下次打开应用时候,再自动加载这些信息。下面将介绍windows8开发中如何存储数据。  一.本地数据存储  在wp中我们使用IsolatedStorageSettings进行本地数据存储,在win8中也提供类似的方法进行存储,我们使用ApplicationData.Current.LocalSettings。下面将通过实例进行描述:  在节目上添加姓名、年龄、性别三个控件,代码如下:1234567891011121314男15女161718192021222324  新建类AppDataHelper.cs,引用命名空间usingWindows.Storage。我们将读取和保存封装成共通,方便调用。  保存数据:1///2///保存数据3///4///数据类型5///键6///值7publicstaticvoidSave(stringkey,Tvalue)8{9ApplicationData.Current.LocalSettings.Values[key]=value;10}  读取数据:1///2///读取数据3///4///数据类型5///键6///值7publicstaticTRead(stringkey)8{9if(ApplicationData.Current.LocalSettings.Values.ContainsKey(key))10{11return(T)ApplicationData.Current.LocalSettings.Values[key];12}13else14{15returndefault(T);16}17}  删除数据:1///2///移除数据3///4///键5///成功true/失败false6publicstaticboolRemove(stringkey)7{8returnApplicationData.Current.LocalSettings.Values.Remove(key);9}  我们只要在需要存储或者读取数据的地方进行调用,就可以了。1privatevoidbtnSave_Click(objectsender,RoutedEventArgse)2{3AppDataHelper.Save("name",txtName.Text.Trim());4AppDataHelper.Save("age",int.Parse(txtAge.Text.Trim()));5AppDataHelper.Save("sex",cbxSex.SelectedIndex);6}7privatevoidbtnRead_Click(objectsender,RoutedEventArgse)8{9txtName.Text=AppDataHelper.Read("name");10txtAge.Text=AppDataHelper.Read("age").ToString();11cbxSex.SelectedIndex=AppDataHelper.Read("sex");12}  那么我们保存的数据保存到哪里去了呢?我们应该如何找到他们,别急,我们下面开始找保持的数据。  打开C:\Users\\AppData\Local\Packages\\Settings\settings.dat,user_name对应当前登录的用户名,packpage对应此应用的唯一标识,在Package.appxmanifest中我们可以找到它:    此文件为.dat后缀,我们需要用注册表工具打开它,开始->运行(win+R键),输入Regedit,在打开的窗口里面选择HKEY_LOCAL_MACHINE,    然后选择文件->加载配置单元,选择settings.dat文件,打开填入项名称,确定之后可以看到保存的数据会显示在其中。      双击name,打开,我们可以看到存储的数据值。    那么我们是否能像wp那样存储一个对象到本地存储呢,答案是否定的。win8中只能存储一些简单类型,如int、bool、string等  下面有一个Person对象:1[DataContract]2publicclassPerson3{4[DataMember]5publicstringName{get;set;}6[DataMember]7publicintAge{get;set;}8[DataMember]9publicintSex{get;set;}10}  进行存储:1Personperson=newPerson()2{3Name=txtName.Text.Trim(),4Age=int.Parse(txtAge.Text.Trim()),5Sex=cbxSex.SelectedIndex6};7AppDataHelper.Save("person",person);  此时会报错,提示不支持此类型存储。    那么我们应该如何存储一个对象呢?下面我们将介绍文件存储。  二.文件存储  对于那些比较复杂的数据类型,我们需要将其存储为文件的形式存储在应用中。StorageFile的存储,以文件的形式进行存储存入数据。  新建一个类,LocalFileHelper.cs  存储文件:1///2///存储数据///3///数据类型4///文件名称5///数据6///无7publicasyncstaticTaskSave(stringfileName,Tdata)8{9//取得当前程序存放数据的目录10StorageFolderfolder=Windows.Storage.ApplicationData.Current.LocalFolder;11//创建文件,如果文件存在就覆盖12StorageFilefile=awaitfolder.CreateFileAsync(fileName,CreationCollisionOption.ReplaceExisting);13using(StreamnewFileStream=awaitfile.OpenStreamForWriteAsync())14{15DataContractSerializerser=newDataContractSerializer(typeof(T));16ser.WriteObject(newFileStream,data);17newFileStream.Dispose();18}19}  读取文件:1///2///读取数据3///4///数据类型5///文件名称6///数据7publicasyncstaticTaskRead(stringfileName)8{9Tt=default(T);10try11{12StorageFolderfolder=Windows.Storage.ApplicationData.Current.LocalFolder;13StorageFilefile=awaitfolder.GetFileAsync(fileName);14if(file==null)15returnt;16StreamnewFileStream=awaitfile.OpenStreamForReadAsync();17DataContractSerializerser=newDataContractSerializer(typeof(T));18t=(T)ser.ReadObject(newFileStream);19newFileStream.Dispose();20returnt;21}22catch(Exception)23{24returnt;25}26}  删除文件:1///2///删除文件3///4///文件名称5///成功true/失败false6publicasyncstaticTaskDelete(stringfileName)7{8StorageFolderfolder=Windows.Storage.ApplicationData.Current.LocalFolder;9StorageFilefile=awaitfolder.GetFileAsync(fileName);10if(file!=null)11{12try13{14awaitfile.DeleteAsync();15}16catch(Exception)17{18returnfalse;19}20}21returntrue;22}  使用方法:1Personperson=newPerson()2{3Name=txtName.Text.Trim(),4Age=int.Parse(txtAge.Text.Trim()),5Sex=cbxSex.SelectedIndex6};78awaitLocalFileHelper.Save("person.xml",person);910Listlist=newList();11list.Add(person);12list.Add(person);13awaitLocalFileHelper.Save("personList.xml",list);141516PersonnewPerson=awaitLocalFileHelper.Read("person.xml");17ListpersonList=awaitLocalFileHelper.Read("personList.xml");  文件在哪里?  同样我们打开C:\Users\user_name\AppData\Local\Packages\package\LocalState文件夹,下面就有我们保持的文件,打开文件,保存文件的内容格式为xml:27BetterChaner0  三.使用Sqlite进行数据存储  Sqlite现已提供对WindowsRT和Windows8Metro应用的支持.  首先,在工具,选择扩展与更新中,选择联机,在搜索框内输入sqlite,找到SQLiteforWindowRuntime,下载安装。    安装完成之后重启VS,右击项目添加引用,选择Windows->扩展,找到Mircosoftvisualc++runtimepackage和sqliteforwindowsruntime,打勾,确定。    由于目前Sqlite不支持AnyCPU,所以我们将项目改成X64,右击解决方案,属性,修改之。    然后右击引用,选择管理Nuget程序包,联机搜索sqlite-net,下载安装。  我们发现项目工程中多了2个类文件,SQLite.cs和SQLiteAsync.cs    基本操作:1//创建数据库2stringdbRootPath=Windows.Storage.ApplicationData.Current.LocalFolder.Path;3SQLiteConnectiondb=newSQLiteConnection(Path.Combine(dbRootPath,"myApp.sqlite"));45//创建表6db.CreateTable();78//插入一条数据9db.Insert(newPerson(){Name="BetterChaner",Age=27,Sex=1});1011//插入多条数据12Listlist=newList();13list.Add(newPerson(){Name="Zhangsan",Age=27,Sex=1});14list.Add(newPerson(){Name="Lisi",Age=32,Sex=0});15list.Add(newPerson(){Name="Wangwu",Age=24,Sex=1});16db.InsertAll(list);1718//查询数据19Listlist2=db.Query("select*fromPerson");2021//更新数据22SQLiteCommandcmd=db.CreateCommand("updatePersonsetAge=21whereName='Lisi'");23cmd.ExecuteNonQuery();2425//删除一条数据26db.Delete(newPerson(){Name="Zhangsan",Age=27,Sex=1});27//删除全部数据28db.DeleteAll();  数据存储的位置为:C:\Users\\AppData\Local\Packages\\LocalState\文件夹下的myApp.sqlite  四.SqlCE  有了Sqilte,SqlCE不太经常会用到了,在这里就不写出实例了,与wp中类似。  小结  以上为windowsstoreapp开发中可以使用的几种存储数据的方式,可以根据数据大小、作用以及类型选择应该使用哪一种存储方式。追问

哥哥,你在说什么......我需要把不同手机上的数据,统一提交到服务器上......我想知道我应该租用什么样的服务器.................

温馨提示:答案为网友推荐,仅供参考