【发布时间】:2012-08-19 15:44:29
【问题描述】:
我正在使用 Windows 8 发布预览版和 C#(VS 2012) 开发 Metro 应用程序,我从 link 下载了 SQLite 3.7.13,并使用 this 程序成功地与我的应用程序集成,通过使用以下代码,我可以创建表格和插入数据
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "test.db");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
db.CreateTable<Test>();
db.RunInTransaction(() =>
{
for (int i = 0; i < 10; i++)
{
db.Insert(new Test() { id = i,dept = "CS", Firstname = "First" + i.ToString(), Lastname = "Last" + i.ToString() });
}
});
}
在哪里测试我的内部类
class Test
{
[AutoIncrement,PrimaryKey]
public int id { get; set; }
public string dept { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public override string ToString()
{
return string.Format("{0},{1}", Lastname, Firstname);
}
}
通过使用下面的代码,我可以检索测试表中的所有记录
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "test.db");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
var data = db.Table<Test>();
}
所以我的问题是我们如何在 SQLLite 中提供准备好的语句? 例如:如果我想在我的表中查找部门“CS”的记录数,并且 如果我只想从我的表中获取部门“CS”的记录怎么办 请帮助我,在此先感谢。
【问题讨论】:
标签: c# sqlite windows-8 microsoft-metro windows-runtime