xamarin SQLite路径
xamarin使用SQLite时对应的访问路径各个平台不一样,需要单独引用。在使用前添加SQLite引用包,在解决方案上右击选择解决方案的Nuget管理选项,在浏览中输入sqlite-net-pcl,选择sqlite-net-pcl这个安装好就可以了,请认准安装包,不要装错了,有很多类似的包,但是不是同一个人写的。
下面各平台罗列代码:
Windows8.1:
public SQLiteConnection GetConnection(string dbName) {
var sqliteFilename = string.Format("{0}.db3", dbName);
string documentsPath = global::Windows.Storage.ApplicationData.Current.LocalFolder.Path;
var path = Path.Combine(documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection(path);
}
在windows Phone下注意要添加一个引用:引用>>添加引用>>windows phones8.1>>扩展>>Microsoft Visual C++Runting Time Packge for windows Phone
UWP:
public SQLiteConnection GetConnection(string dbName) {
var sqliteFilename = string.Format("{0}.db3", dbName);
string documentsPath = global::Windows.Storage.ApplicationData.Current.LocalFolder.Path;
var path = Path.Combine(documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection(path);
}
Android:
public SQLite.SQLiteConnection GetConnection(string dbName)
{
var sqliteFilename = string.Format("{0}.db3", dbName);
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection(path);
}
IOS:
public SQLite.SQLiteConnection GetConnection(string dbName)
{
var sqliteFilename = string.Format("{0}.db3", dbName);
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder
var path = Path.Combine(libraryPath, sqliteFilename);
return new SQLite.SQLiteConnection(path);
}
在使用的时候也要注意下,下面罗列一下。
案例一,在我们使用new SQLiteConnection().Insert(new model)时注意,这里的Insert方法虽然可以输入LIst<T>类型,但是掉用的时候会报错,如uwp上报Parameter count mismatch.等,无法插入数据,记得这个方法只能插入一条数据,不能批量操作,楼主在这里栽了跟头。
希望以上东西对于你写xamarin有帮助。欢迎交流。
xamarin SQLite路径的更多相关文章
- Xamarin SQLite教程Xamarin.iOS项目添加引用
Xamarin SQLite教程Xamarin.iOS项目添加引用 使用直接方式访问SQLite数据库,需要将System.Data和Mono.Data.SQlite库导入到创建的项目中.下面将分别讲 ...
- Xamarin SQLite教程数据库访问与生成
Xamarin SQLite教程数据库访问与生成 在本教程中,我们将讲解如何开发SQLite相关的App.在编写程序前,首先需要做一些准备工作,如了解Xamarin数据库访问方式,添加引用,构建使用库 ...
- QT里使用sqlite的问题,好多坑
1. 我使用sqlite,开发机上好好的,测试机上却不行.后来发现是缺少驱动(Driver not loaded Driver not loaded),代码检查了又检查,发现应该是缺少dll文件(系统 ...
- Sqlite数据库简介
在应用sqlite之前需要添加sqlite库,那么我们就会发现有3和3.0的区别,开始我也并不懂,后才知道: 实际上libsqlite3.dylib本身是个链接,它指向libsqlite3.0.dyl ...
- iOS 中SQLite数据库操作
在iOS中实现SQLite数据库的操作:1.导入框架(libsqlite3.0.tbd) 2.导入头文件<sqlite3.h> 3.实现数据的增删改查 实现简单 SQLite数据库操作 的 ...
- PHP PDO sqlite ,Unable to Open database file的解决方法
t.php在网站的根目录. fdy.db在inc文件夹下; t.php中sqlite路径写成相对路径 $db = new PDO('sqlite:inc/fdy.db'); 开始提示 Fatal er ...
- C# Android 开发中使用 Sqlite.NET ORM
开发环境:VS2015 Xamarin Sqlite.NET ORM 不就相当于 Entiry Framework For Xamarin 吗? 相当于用 C# 开发安卓程序访问 Sqlite 可以使 ...
- flask-sqlalchemy、pytest 的单元测试和事务自动回滚
flask-sqlalchemy.pytest 的单元测试和事务自动回滚 使用 flask-sqlalchemy 做数据库时,单元测试可以帮助发现一些可能意想不到的问题,像 delete-cascad ...
- Python之路-(Django进阶一)
Django请求生命周期: 首先,客户端发送请求到服务器的urls库,通过匹配url后面的关键字,去找指定app里面的的view. 然后,app通过判断,拿到数据库数据和html模板文件. 最后,将拿 ...
随机推荐
- 用栈解决Largest Rectangle问题
一问题描述 Given n non-negative integers representing the histogram's bar height where the width of each ...
- python面向对象中的__init__方法怎么理解?
我们在学习python类的时候,总会碰见书上的类中有__init__()这样一个函数,很多同学百思不得其解,其实它就是python的构造方法. 构造方法类似于类似init()这种初始化方法,来初始化新 ...
- 阿里云安装Tomcat
1.Apache官方网站下载Tomcat http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0 ...
- Hyper-v虚拟机文件VHDX与VHD的格式转换
今天遇到一个坑,我在本机(windows 10)上创建的CentOS虚拟机作为docker的宿主机,部署了gitlab等容器,准备迁移到服务器上的时候,发现始终无法导入,提示必须通过Hyper-v导出 ...
- c# WebBrower 与 HttpRequest配合 抓取数据
今天研究一个功能,发现一个问题. 通过webbrower模拟用户自动登录可以完成,并且可以取到相对应的页面内容. 但是如果页面中通过ajax,动态加载的内容,这种方式是取不到的,于是用到了httpRe ...
- vim : 依赖: vim-common (= 2:7.3.429-2ubuntu2.1) 但是
Ubuntu 12.10 安装vim出错[日期:2013-01-18] 来源:Linux社区 作者:Cubernet [字体:大 中 小] 在Ubuntu 12.10中安装vim时出现了如下提示:正在 ...
- disconf使用
1.创建app,确定version 2.创建配置文件redis.config 3.选择app下env环境,上传redis.config到disconf 4.创建disconf.properties到c ...
- Refresh recovery area usage data after manually deleting files under recovery area
Original source: http://www.dba-oracle.com/t_v$_flash_recovery_area.htm If you manually delete files ...
- 【IOS】异步调用--- 简单使用记录
/×× ×实现功能:店铺被删除后,先显示提示toast.然后,页面休眠5秒后,再返回到店铺列表页面.×/ - (void)processDeleteShopError { _isLoadingData ...
- 《理解 ES6》阅读整理:函数(Functions)(三)Function Constructor & Spread Operator
增强的Function构造函数(Increased Capabilities of the Function Constructor) 在Javascript中Function构造函数可以让你创建一个 ...