I have two questions.
-
How can I get the SQLite Db to store data? The db is created and I can find the db at its FilePath location, but I never see any data.
-
How do I change the location to save the data in a local folder, not in the Users… appdata folder?
Here is my code:
Database db = new Database(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,"alpha2.db"));
// Database db = new Database("c:\\Projects\\alpha2.db");
Statement stm;
stm = db.PrepareStatement("CREATE TABLE IF NOT EXISTS person(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, data BLOB)");
stm.Execute();
stm.Dispose();
stm=db.PrepareStatement("INSERT INTO person(name,age VALUES(?,?)");
stm.BindParamText(1,"John Doe");
stm.BindParamInt(2,35);
stm.Execute();
stm.Dispose();
long insertRowId = db.LastInsertRowId;
stm=db.PrepareStatement("SELECT * FROM person");
while(stm.GetNextRow())
{
int id=stm.GetIntAt(0);
string name=stm.GetTextAt(1);
textBlock1.Text=name.ToString();
}
stm.Dispose();
db.Dispose();
TIA, this has been a two-day head banger.
The syntax on your insert query looks wrong. It should be more like …
(Added a close paren after age.)
You can’t write to an arbitrary location on the user’s drive from a Metro Style app. LocalFolder is your best bet.
Edit for comment: Check out Tim’s article on Sqlite for syntax for local folder.