C # Operation SQLite

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.