c# - SQLite and delete command -


 bool ret = false; try { sqliteconnection sqlconn = new sqliteconnection("data source=" + m_dbname); sqlconn.open(); sqlitecommand sqlcomm = sqlconn.createcommand(); sqlcomm.commandtext = "delete " + sztablename+" name="+name+""; sqlitedataadapter sqladapter = new sqlitedataadapter(sqlcomm); if (null == sqladapter) { ret = false; } else { ret = true; } sqlconn.close(); return ret; } catch (sqliteexception sqlex) { console.writeline(sqlex.message); return false ; } 

i have code delete row in sqlite database, nothing done after click delete button.

instead of using dataadapter execute command directly:

using(sqliteconnection sqlconn = new sqliteconnection("data source=" + m_dbname)) { sqlconn.open(); //create command sqlcommand.executenonquery(); } 

you shouldn't swallow exceptions thrown executenonquery method unless can sensibly handle them. should use parameterised queries instead of manually creating queries concatenating strings. should make sure close connection after have finished using shown.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -