Windows 8.1 ストア アプリを開発しようとしています。他の困難の中で、where 句に 2 つのパラメーターを使用して sqlite データベースからレコードを取得する必要があります。where 句で 1 つのパラメーターを使用して正常にクエリを実行できますが、2 つのパラメーターを使用しようとするとすべてがクラッシュします。これが私のコードです:
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
変数が定義されている行を参照してください。この行のコメントアウトされたバージョンは正常に機能します。変数定義を 2 つのパラメーター クエリ (テーブル クエリ アプローチに 2 番目のパラメーターを追加する方法がわからなかったため、別の方法を使用して取得) に置き換えると、クラッシュします。
ご協力いただきありがとうございます。自分のやっていることを半分しか理解できなくてすみません。