how to create sqlite database in wpf? -


i new windows desktop application development.will please suggest me how create sqlite database in windows presentation foundation(wpf)?

you need 2 things:

  1. add sqlite dll application references
  2. write class builds db.

for example:

using system; using system.collections.generic; using system.data.sqlite; using system.diagnostics; using system.io; using system.linq; using system.text; using system.threading.tasks;  namespace database { public class dbcreator {     sqliteconnection dbconnection;     sqlitecommand command;     string sqlcommand;     string dbpath = system.environment.currentdirectory + "\\db";     string dbfilepath;     public void createdbfile()     {         if (!string.isnullorempty(dbpath) && !directory.exists(dbpath))             directory.createdirectory(dbpath);         dbfilepath = dbpath + "\\yourdb.db";         if (!system.io.file.exists(dbfilepath))         {             sqliteconnection.createfile(dbfilepath);         }     }      public string createdbconnection()     {         string strcon = string.format("data source={0};", dbfilepath);         dbconnection = new sqliteconnection(strcon);         dbconnection.open();         command = dbconnection.createcommand();         return strcon;     }      public void createtables()     {         if (!checkifexist("my_table"))         {             sqlcommand = "create table my_tbale(idnt_test integer primary key autoincrement,code_test_type integer";             executequery(sqlcommand);         }      }      public bool checkifexist(string tablename)     {         command.commandtext = "select name sqlite_master name='" + tablename + "'";         var result = command.executescalar();          return result != null && result.tostring() == tablename ? true : false;     }      public void executequery(string sqlcommand)     {         sqlitecommand triggercommand = dbconnection.createcommand();         triggercommand.commandtext = sqlcommand;         triggercommand.executenonquery();     }      public bool checkiftablecontainsdata(string tablename)     {         command.commandtext = "select count(*) " + tablename;         var result = command.executescalar();          return convert.toint32(result) > 0 ? true : false;     }       public void filltable()     {         if (!checkiftablecontainsdata("my_table"))         {             sqlcommand = "insert my_table (code_test_type) values (999)";             executequery(sqlcommand);         }     }   } } 

good luck!


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -