c# - Unable to delete a record in Sqlite db in Windows Store app -


kind of new in windows 8 app development, have issue on particular part of code. app uses sqlite database, , can't delete record using primary key. use c# way. here snippet unable delete record using primary key.

> >

case "ok":

                 string result = string.empty;                  int chapterindex=0;                 using (var db = new sqlite.sqliteconnection(path))                 {                       var questionq = (db.table<chapter>().where(                         c => c.chaptername == chapterselected)).single();                     chapterindex = questionq.index;                  //the above query executes fine                   //  result = chapterselected;  chapterselected string containing >//chapter name.                      try                     {//this 1 wouldn't                         db.delete<chapter>(chapterindex);                      }                     catch(exception ex)                     {                         pagetitle.text = ex.tostring();                     } 

my mvvm class chapter is...

[table("chapter")] public class chapter {     public int index { get; set; }     public string chaptername { get; set; }     public int chapterno { get; set; }  } 

i did not declare index primary key in above class because using autoincrement field in db. here table enter image description here

everything works fine(insert, select, deleteall,drop table etc...except deleting single row.)

any appreciated!

this answer assumes using sqlite-net database access layer.

the problem class definition of chapter not match table (sql) definition. missing primarykey , autoincrement attributes class definition:

[table("chapter")] public class chapter {     [primarykey, autoincrement]     public int index { get; set; }     public string chaptername { get; set; }     public int chapterno { get; set; } } 

sqlite-net not read sql table information, not know column primary key. why having problem deleting.

unrelated specific question, autoincrement attribute useful inserting records, cause sqlite-net set class index field same sqlite generated value primary key.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -