Reputation: 21
I am totally new in WP development, but I am interested to learn.
I have a little problem when I try to insert data into my SQLITE database. The weird thing is when I input the data there is no problem and it doesn't throw an exception.
When I try to close my apps and open it again from simulator the data is showing, but when I open my database.sqlite from Sqlite manager firefox addons, the data is not there. The table is still empty.
Please help me out.
private void btnAddExpense_Click(object sender, RoutedEventArgs e)
{
DateTime datenow = DateTime.Now;
String format = "yyyy-MM-dd HH:mm:ss";
String d = datenow.ToString(format);
String formatid = "yyyyMMddHHmmss";
String id = datenow.ToString(formatid);
int rec;
String strInsert = " Insert into Expense (date,id_category,nominal,detail,icon) values (@date,@id_category,@nominal,@detail,@icon)";
Expense tst = new Expense
{
date = d,
id_category = cat,
nominal = amount.Text,
detail = detail_txt.Text,
icon = iconUrl,
};
rec = (Application.Current as App).db.Insert<Expense>(tst, strInsert);
if (rec == 1)
MessageBox.Show("Row inserted!");
else
MessageBox.Show("Row NOT inserted.");
}
and I use Dbhelper.cs to insert data
public int Insert<T>(T obj, string statement) where T : new()
{
try
{
Open();
SQLiteCommand cmd = db.CreateCommand(statement);
int rec = cmd.ExecuteNonQuery(obj);
return rec;
}
catch (SQLiteException ex)
{
System.Diagnostics.Debug.WriteLine("Insert failed: " + ex.Message);
throw ex;
}
}
Any suggestion would be very helpful.
Upvotes: 1
Views: 1080
Reputation: 26
Sqlite data are copied to isolated storage first, then you insert record to table. So, if you want to view newest DB, you must open file .sqlite in isolated storage, not at project folder.
Upvotes: 1