【发布时间】:2015-12-20 01:02:53
【问题描述】:
我正在 UWP 中制作电影应用程序,如果用户喜欢电影,我想存储电影的 id。我已经尝试过使用 txt 但访问被拒绝错误有很多问题。所以我决定使用 sqlite。
我用它来获得stard: https://code.msdn.microsoft.com/windowsapps/Implement-SQLite-Local-8b13a307#content
我已经搜索了一段时间,我发现的所有信息都可以与 sqlite pcl 一起使用。看起来我找到的示例使用的许多方法都存在。
所以看来那里的例子很少..也许你们可以以正确的方式推动我..
这是我到目前为止的代码:
private void LikeIt()
{
var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Filmdb.sqlite");
using (SQLite.Net.SQLiteConnection conn =
new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))
{
if (File.Exists(sqlpath))
{
AdMovieID();
}
else
{
conn.CreateTable<MovieID>();
AdMovieID();
}
}
}
private void AdMovieID()
{
var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Filmdb.sqlite");
SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath);
//This is where i have tried some of the things i have found
// like this:
//SQLite.Net.SQLiteCommand insertSQL =
//new SQLite.Net.SQLiteCommand("INSERT INTO MovieID(ID) VALUES(?), conn)<-- error: dosent work no constructor that takes arguments;
//insertSQL.Parameters.Add(MovieID.ID);
//Just to test if something is saved
var allaId = conn.Find<MovieID>(sqlpath).ID;//<-- just tried this and it dosent work either "Object reference not set to an instance of an object."
foreach (var id in allaId)
{
Test.Text = id.ToString();
}
}
我在 SQLite 中使用的类:
public class MovieID
{
public string ID { get; set; }
}
【问题讨论】: