0

I'm using SQLite.net (https://github.com/praeclarum/sqlite-net) in my Xamarin Forms project and trying to save a user's projects in the database.

In order to make sure there won't be any duplicates, I want to first clear the table by calling:

await _db.DeleteAllAsync<Project>();

This is throwing the following exception if I never saved any data in the database.

SQLite.SQLiteException: 'no such table: Project'

I realize I can do this in a try/catch block but is there a way to clear a particular table before saving any data in it without getting exceptions in case no data has ever been saved in it before?

P.S. I'm aware of the await _db.InsertOrReplaceAsync(List<Project>) but when I tried that I get the following error:

System.ArgumentException: 'method arguments are incompatible'

I don't know what to make of this exception as it's pretty vague.

How do I make sure my table is clear before saving some data in it?

Sam
  • 26,817
  • 58
  • 206
  • 383
  • 1
    have you created the table first? You could also query the table first to see if it returns any rows before attempting to clear it. Your `InsertOrReplaceAsync` is failing because you're passing it a `List` instead of a single `Project` – Jason May 07 '22 at 22:48
  • How do I save multiple `Project`'s in a table? – Sam May 07 '22 at 22:52
  • Quick search indicates I have to serialize my data first. Is that the only way to do it? – Sam May 07 '22 at 22:55
  • 1
    use `InsertAll` or `InsertAllAsync` – Jason May 07 '22 at 22:59

0 Answers0