Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
最近研究如何在VS2013 Update 2环境下创建的Windows 8.1 store app 和Windows Phone 8.1 (WinRT和Silverlight)环境下使用SQLite数据库存储关系型本地数据库。其实很简单,只要在项目的References里选择Manage NUGet Packages,在线查找Portable Class Library for SQLite,安装,如图一。这是有MSOpenTech开发的,目前最新版本是3.8.5.0.
(图一)
之后,依据你的项目是Win8还是WP8应用,在Refereces里会自动添加相应的3个Library,如图二和图三
(图二)
(图三)。
之后可以在App.xaml.cs创建一个简单的方法如下测试一下:
private void LoadDatabase()
{
// Get a reference to the SQLite database
var conn
= new SQLiteConnection("sqlitepcldemo.db");
string sql = @"CREATE TABLE IF NOT EXISTS
Customer (Id INTEGER PRIMARY
KEY AUTOINCREMENT,
Name VARCHAR( 140 ),
City VARCHAR( 140 ),
Contact VARCHAR(
140 )
);";
using (var
statement = conn.Prepare(sql))
{
statement.Step();
}
}
然后在App启动时调用LoadDatabase()方法,你会发现程序可以正常运行,说明SQLite调用成功。