dimanche 22 février 2015

SQLiteException when trying to Insert (Windows Phone 8)

First time working with SQLite and Windows Phone for that matter, and I'm getting an SQLiteException when I try and insert data. When I break from the exception, it highlights "throw" in the "RunInTransaction" method in SQLite.cs. I've looked around and I can't find how I'd solve this problem.


One thing I'm thinking is maybe I'm doing my CRUD methods wrong. I have several model classes and I wanted to create CRUD methods that use generic types so that the methods could be used with all the model classes rather than having to create 6-7 CRUD solutions for each model.


Here's how I'm doing my insert which I'm testing atm;



public void Insert<T>(T obj)
{
using (App.SQLiteCon = new SQLiteConnection(App.DBPath))
{
App.SQLiteCon.RunInTransaction(() =>
{
App.SQLiteCon.Insert(obj);
});
}
}


Then I'm using the method in my ViewModel like;



public ICommand SaveButtonCommand
{
get
{
return _saveButtonCommand
?? (_saveButtonCommand = new Resources.ActionCommand(() =>
{
Models.SleepTrackerModel insertSleepData = new Models.SleepTrackerModel
{
Date = SleepDate,
SleepTime = SleepTime,
WakeTime = WakeTime,
Duration = SleepDuration,
Rating = SleepRating
};
_dbHelper.Insert<Models.SleepTrackerModel>(insertSleepData);
ShowDataPopup = false;
ShowDataSavedPopup = true;
}));
}
}


I've put a few debug lines in my code to see if my tables, etc. are created and all that is fine, so I'm puzzled right now on how to get around this. Any help would be great.


Aucun commentaire:

Enregistrer un commentaire