试图开发Windows 8.1商店应用程序。在其他困难中,我需要从where子句中使用两个参数从sqlite数据库检索记录。我可以用where子句中的一个参数成功查询,但是当我尝试使用两个参数时,它会崩溃一切。这里是我的这段代码:具有多个WHERE条件的SQLite数据库查询
public string SaveMaint(MaintViewModel Maintenance)
{
string result = string.Empty;
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
string change = string.Empty;
try
{
var existingmaintenance = db.Query<maintenance> ("select * from maintenance where VehID = ? AND MaintID = ?", new String[] {Maintenance.Maintid, Maintenance.Vehicleid});
// var existingmaintenance = (db.Table<maintenance>().Where
// (c => c.MaintID == Maintenance.Maintid).SingleOrDefault());
if (existingmaintenance != null)
{
existingmaintenance.VehID = Maintenance.Vehicleid;
existingmaintenance.MaintID = Maintenance.Maintid;
existingmaintenance.ServiceDate = Maintenance.Servicedate;
existingmaintenance.ServiceCost = Maintenance.Servicecost;
existingmaintenance.ServiceLocation = Maintenance.Servicelocation;
existingmaintenance.ServiceNote = Maintenance.Servicenote;
existingmaintenance.ServiceOdom = Maintenance.Serviceodom;
int success = db.Update(existingmaintenance);
}
else
{
int success = db.Insert(new maintenance()
{
VehID = Maintenance.Vehicleid,
MaintID = Maintenance.Maintid,
ServiceDate = Maintenance.Servicedate,
ServiceCost = Maintenance.Servicecost,
ServiceLocation = Maintenance.Servicelocation,
ServiceNote = Maintenance.Servicenote,
ServiceOdom = Maintenance.Serviceodom
});
}
result = "Success";
}
catch
{
result = "This project was not saved.";
}
}
return result;
}
请参考其中existingmaintenance
变量定义行。该行的注释版本正常工作。当我将变量定义替换为两个参数查询(由于我无法弄清楚如何将第二个参数添加到表查询方法中),它会崩溃。
感谢您提供任何帮助。对不起,我只有一半明白我在做什么。
什么样的ORM您使用的是?它似乎与扩展Dapper,但我不知道。 – Steve