Sqllite Database Operation classes

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data;usingSystem.Data.SQLite;namespacefaceattendance{classDBHelper { PublicSqliteconnection Conn;  PublicDBHelper () {connectdatabase (); }        Private voidConnectdatabase () {conn=NewSqliteconnection ("Data source=. \\.. \\.. \\FACEINFO.DB3; Verson = 3;");//Create a DB instance, specify the file locationConn. Open ();//Open the database and create it automatically if the file does not exist            if(conn = =NULL)Throw NewException ("database connection failed. Check to see if the database file exists. "); }         Public voidInsertPerson (intIdstringNamestringSexstringPositionstringFaceinfo,stringdes) {            stringsql =NULL; if(des = =NULL) {SQL="INSERT into info values ("+14061143+", '"+ name +"', '"+ Sex +"', '"+ Position +"',"+ des +");"; }            Else{SQL="INSERT into info values ("+14061143+", '"+ name +"', '"+ Sex +"', '"+ Position +"', '"+ des +"');"; } sqlitecommand Command=Newsqlitecommand (SQL, conn); Command.            ExecuteNonQuery (); Command.        Dispose (); }         Public voidInsertattendance (intIdstringTime ) {            stringsql ="INSERT into signinfo values ("+id+", '"+time+"');"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Command.            ExecuteNonQuery (); Command.        Dispose (); }         PublicList<peopleinfo>Getpeopleinfo () {List<peopleinfo> FACERLT =NewList<peopleinfo>(); stringsql ="SELECT * from info;"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Sqlitedatareader Reader=command.            ExecuteReader (); intj =0;  while(reader. Read ()) {J++; Peopleinfo people=NewPeopleinfo (); People. Id= Reader. GetInt32 (0); People.name= (string) reader["NAME"]; People.sex= (string) reader["SEX"]; People.position= (string) reader["JOB"]; stringFS = (string) reader["Faceinfo"]; string[] FSA = fs. Split (';');  for(inti =0; I < -; i++) People.faceinfo[i]= (float) convert.todouble (Fsa[i]); People.des= (string) reader["MSG"];            Facerlt.add (people); } command.            Dispose (); Reader.            Dispose (); returnFACERLT; }         Public voidInsertpersonrecord (stringNamestringTime ) {            stringsql ="INSERT into Personrecord values ('"+ name +"', '"+ Time +"');"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Command.            ExecuteNonQuery (); Command.        Dispose (); }         PublicPeopleinfo Getpersoninfo (intId) {stringsql ="SELECT * from info WHERE Id ="+Id; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Sqlitedatareader Reader=command.            ExecuteReader (); Reader.            Read (); Peopleinfo people=NewPeopleinfo (); People. Id= Reader. GetInt32 (0); People.name= (string) reader["NAME"]; People.sex= (string) reader["SEX"]; People.position= (string) reader["JOB"]; People.des= (string) reader["MSG"]; returnpeople; }    }}

Sqllite Database Operation classes

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.