Win10之UWP的数据存储
来源:互联网 发布:淘宝偷换宝贝怎么举报 编辑:程序博客网 时间:2024/06/04 18:27
我们知道通常我们开发的时候都要考虑把用户的数据存储到一个数据库里面,而这个数据库则考虑到了整个应用的性能上面,这里我们不考虑SQL server的数据库,我们考虑较为轻量的数据库进行存储。
首先我们新建一个项目,然后把界面用代码处理一下
<Grid.RowDefinitions> <RowDefinition Height="100"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Text="把数据存储入数据库" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="楷体" FontSize="24" Foreground="Green"/> <TextBlock Text="MySQLite Connection Test" HorizontalAlignment="Center" FontSize="36" FontFamily="Gabriola" Grid.Row="1" Foreground="Green"/> <TextBlock Text="用户账号:" Grid.Row="2"/> <TextBox x:Name="MyTextBox" Grid.Row="3" PlaceholderText="name"/> <TextBlock Text="用户密码:" Grid.Row="4"/> <PasswordBox x:Name="MyPassWordBox" Grid.Row="4" PlaceholderText="password" Margin="0,20,0,0"/>
<Page.BottomAppBar> <CommandBar IsOpen="False" ClosedDisplayMode="Minimal" Background="Green"> <AppBarButton x:Name="Add" Label="Add" Icon="Add" Click="Add_Click"/> <AppBarButton x:Name="Show" Label="Show" Icon="Zoom" Click="Show_Click"/> </CommandBar> </Page.BottomAppBar>
然后我们再来处理一下界面后台的事件代码处理
string path; SQLite.Net.SQLiteConnection conn;
到这里的时候我们忘记了一件事,没有安装相关的插件,所以再安装下数据库插件
还要再安装一个插件
紧接着我们安装好了插件后,我再来添加引用,让项目得到插件的支持
好了,这次可以好好的写代码了,我在项目中新增了一个类
public class MyTest { [PrimaryKey,AutoIncrement] public int Id { get; set; } public string Name { get; set; } public string PassWord { get; set; } }
我回到我们的主界面的后台写写代码
path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path, "db.MySQLite"); conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path); conn.CreateTable<MyTest>();
新增事件的后台的代码处理
private void Add_Click(object sender, RoutedEventArgs e) { var add = conn.Insert(new MyTest() { Name = MyTextBox.Text, PassWord = MyPassWordBox.Password }); Debug.WriteLine(path); }
这里的这个方法是在visual studio 2015中显示实时新增的数据
private void Show_Click(object sender, RoutedEventArgs e) { var query = conn.Table<MyTest>(); string result = String.Empty; foreach (var item in query) { result = String.Format("{0}:{1}:{2}", item.Id, item.Name,item.PassWord); Debug.WriteLine(result); } }
代码写到这里就已经写完了,我们看看目的达到了没有
我们再来看看第二次的效果如何
很显然我们写的数据成功的存储到了SQLite的数据库中,所以我们的目的就达到了!!!!
2 0
- Win10之UWP的数据存储
- Win10的UWP之进度条
- Win10的UWP开发之Hello World
- Win10的UWP之标题栏的返回键(二)
- Win10的UWP之标题栏的返回键(一)
- Win10开发之UWP控件的隐藏空间
- win10 UWP 九幽数据分析
- win10 uwp InkCanvas控件数据绑定
- 【Win10】UAP/UWP/通用 开发之 SplitView
- win10 uwp 获取指定的文件 AQS
- UWP——HttpClient模拟浏览器的GET、POST请求之Win10 Mobile测试
- win10 UWP读写文件
- Win10/UWP开发-Ink
- win10 uwp 通知Toast
- win10 UWP 显示地图
- win10 uwp 参考
- win10 uwp clone
- Win10/UWP 扫描二维码
- UVA-1587 box
- SSH方式连接Android设备
- Oracle数据库常用操作
- Node.js+Socket.IO实现的WebSocket群聊天室源码
- UVa 401 - Palindromes
- Win10之UWP的数据存储
- UVa 272 - TEX Quotes
- **JAVASCRIPT** DOM对象二——节点与遍历
- Spring transaction事务之roll back回滚
- VS2013 项目项目安装和部署
- POJ1308/HDU1325/NYOJ129-Is It A Tree?,并查集!
- Android中使用Handler造成内存泄露的原因和解决方法
- 为何rem在chrome浏览器上计算出错
- UVA 113 - Power of Cryptography