2016-07-30 16 views
0

Wenn ich meine Anwendung mit SQLite-Datenbank verbinden. Die folgende Ausnahme wirft.Tabelle Zuordnung nicht möglich Fehler in SQlite Verbindung in Windows-Anwendung

An exception of type 'SQLite.SQLiteException' occurred in 
Scrap_Book.Windows.exe but was not handled in user code 

Additional information: no such table: CONTENT 

Ich erstellte die Tabelle mit Hilfe von SqLite Manager ein Adon von Mozila Firefox. Bitte helfen Sie mir, wie ich dieses Problem lösen kann.

  var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MYSCRAPBOOK.sqlite"); 
     using (var db = new SQLite.SQLiteConnection(dbpath)) 

      db.Insert(new CONTENT() 
      { 
       STICKERS=snodesticker 
      }); 


      db.Commit(); 
      db.Dispose(); 
      db.Close(); 
      var line = new MessageDialog("Records Inserted"); 
      await line.ShowAsync(); 
+1

Sie könnten damit beginnen zu akzeptieren, dass die Fehlermeldung tatsächlich korrekt ist. – IInspectable

Antwort

0

Nach Nachricht von Ihrer Ausnahme, die Sie nicht CONTENT Tabelle erstellt haben.

Also, ich denke, Sie müssen Tabelle erstellen, bevor Sie Daten einfügen.

public static string DB_NAME = "ContactsManager.sqlite"; 
public static string DB_PATH = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, DB_NAME));//DataBase Name 

private async Task<bool> CheckFileExistsAsync(string fileName) 
{ 
    try 
    { 
     var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName); 
     return true; 
    } 
    catch 
    { 
    } 
    return false; 
} 

if (!(await CheckFileExistsAsync(DB_NAME))) 
{ 
    using (var db = new SQLiteConnection(DB_PATH)) 
    { 
     db.CreateTable<CONTENT>(); 
    } 
}