usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data.SQLite;usingSystem.Configuration;usingSystem.Collections;usingSystem.Data;usingSystem.IO;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Shapes;usingSystem.Windows;usingSystem.Windows.Controls;namespacedell{ Public classOps { Public Static stringDbPath ="Data Source ="+ Environment.currentdirectory +"/test.db"; PrivateSqlitecommand Command =NewSqlitecommand (); PrivateSqliteconnection connection =NULL; PublicOps () {}//Overloaded Constructors PublicOps (stringDbPath) {Initcon (DbPath); Boolean b=Judgeconn (); if(b = =false) {MessageBox.Show ("Database open failed! "); } } //build connection, and return links Public Staticsqliteconnection Buildconn () {Sqliteconnection conn=NewSqliteconnection (DbPath);//Create a DB instance, specify the file locationConn. Open ();//Open the database and create it automatically if the file does not exist returnConn; } //establish connection, do not open Public voidInitcon (stringDbPath) {Connection=Newsqliteconnection (DbPath); } //Determine connection Status PrivateBoolean Judgeconn () {Boolean IsOpen=true; if(Connection. State! =ConnectionState.Open) {Try { //Initcon (dbPath);connection. Open (); }Catch(Exception) {IsOpen=false; } } returnIsOpen; } //abstract command execution functions that ALTER TABLE data Public intChangecommand (stringCommandText, sqliteparameter[] commandparameters) { intChangedno =0; Judgeconn (); Command. Connection=connection; Command.commandtext=CommandText; if(Commandparameters! =NULL) {command. Parameters.addrange (commandparameters); Changedno=command. ExecuteNonQuery (); } Else{Changedno=command. ExecuteNonQuery (); } returnChangedno; } //abstract a function that does not ALTER TABLE data PublicSqlitedatareader Nochangecommand (stringCommandText) {Judgeconn (); //command. Connection = Connection; //command.commandtext = commandtext;Sqlitecommand Command =NewSqlitecommand (CommandText, connection); Sqlitedatareader SDR=command. ExecuteReader (); returnSDR; } }}
C # Operation SQLite