sqlLite的数据库操作类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SQLite;
namespace FaceAttendance
{
    class DBHelper
    {
        public SQLiteConnection conn;
        public DBHelper()
        {
            ConnectDatabase();
        }
        private void ConnectDatabase()
        {
            conn = new SQLiteConnection("Data Source=..\\..\\..\\faceinfo.db3; verson = 3;"); //创建数据库实例,指定文件位置
            conn.Open(); //打开数据库,若文件不存在会自动创建
            if (conn == null) throw new Exception("数据库连接失败。请检查数据库文件是否存在。");
        }
        public void insertperson(int Id,string name,string sex,string position,string faceinfo,string des)
        {
            string sql = 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 = new SQLiteCommand(sql, conn);
            command.ExecuteNonQuery();
            command.Dispose();
        }
        public void insertAttendance(int Id,string time)
        {
            string sql = "insert into signinfo values("+Id+",‘"+time+"‘);";
            SQLiteCommand command = new SQLiteCommand(sql, conn);
            command.ExecuteNonQuery();
            command.Dispose();
        }
        public List<peopleinfo> getpeopleinfo()
        {
            List<peopleinfo> faceRlt = new List<peopleinfo>();
            string sql = "SELECT * FROM info;";
            SQLiteCommand command = new SQLiteCommand(sql, conn);
            SQLiteDataReader reader = command.ExecuteReader();
            int j = 0;
            while (reader.Read())
            {
                j++;
                peopleinfo people = new peopleinfo();
                people.Id = reader.GetInt32(0);
                people.name = (string)reader["NAME"];
                people.sex = (string)reader["SEX"];
                people.position = (string)reader["JOB"];
                string fs = (string)reader["faceinfo"];
                string[] fsa = fs.Split(‘;‘);
                for (int i = 0; i < 128; i++)
                    people.faceinfo[i] = (float)Convert.ToDouble(fsa[i]);
                people.des = (string)reader["MSG"];
                faceRlt.Add(people);
            }
            command.Dispose();
            reader.Dispose();
            return faceRlt;
        }
        public void insertPersonRecord(string name,string time)
        {
            string sql = "insert into personRecord values(‘ " + name + "‘,‘" + time + "‘);";
            SQLiteCommand command = new SQLiteCommand(sql, conn);
            command.ExecuteNonQuery();
            command.Dispose();
        }
        public peopleinfo getPersonInfo(int Id)
        {
            string sql = "SELECT * FROM info WHERE Id = "+Id;
            SQLiteCommand command = new SQLiteCommand(sql, conn);
            SQLiteDataReader reader = command.ExecuteReader();
            reader.Read();
            peopleinfo people = new peopleinfo();
            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"];
            return people;
        }
    }
}
时间: 2024-08-02 13:36:18

sqlLite的数据库操作类的相关文章

Android打造属于自己的数据库操作类。

1.概述 开发Android的同学都知道sdk已经为我们提供了一个SQLiteOpenHelper类来创建和管理SQLite数据库,通过写一个子类去继承它,就可以方便的创建.管理数据库.但是当我们需要去做增删改查的操作的时候,就得通过getWritableDatabase获取一个SQLiteDataBase然后老老实实去写操作值的put以及查询返回的Cursor处理,其实我们可以搞一个对象来帮我们干这些事情,打造属于你自己的数据库操作类. 2.操作类的初显形 假设现在我们什么都没有,我们要去搞一

PHP 数据库操作类:ezSQL

EZSQL类介绍: 下载地址:http://www.jb51.net/codes/26393.html ezsql是一个小型的快速的数据库操作类,可以让你很容易地用PHP操作各种数据库( MySQL.oracle8/9 .interbase.FireBird.PostgreSQL.MS-SQL.sqlite.sqlite C++). 在你的脚本开头是要包含一个一个PHP文件.然后,你就可以使用更小.更容易的一套ezsql函数来代替标准的PHP数据库函数. 它会自动缓存的查询结果,提供了一系列简单

php中mysql数据库操作类

talk less and show code: <?php/** *以下代码用于数据库操作类的封装* * @author rex<[email protected]> * @version 1.0* @since 2015*/ class Mysql{ //数据库连接返回值 private $conn; /*** [构造函数,返回值给$conn]* @param [string] $hostname [主机名]* @param [string] $username[用户名]* @par

刚整了一个数据库操作类,但是可以用吗?

今天闲来无事,把以前自己搞的一个数据库操作类重新整理了一下,把命名规范了一下,位置和功能重新规划了一下. 源代码下载:http://files.cnblogs.com/xiaoshuai1992/xsFrameWork.SqlServer.zip 请先看图片和介绍 DbOperate文件夹 DbAccess类:核心类,运用Ado.net 对数据库进行操作. DbInParameter :传入DbAccess的参数,如参数,sql语句,sp名称,sp是执行还是返回数据. DbOutParamete

PHP类初识,通用数据库操作类,前端easyui-datagrid,form

实现功能:     左端datagrid显示简略信息,右侧显示选中行详细信息,数据库增删改 (1)点击选中行,右侧显示详细信息,其中[新增].[修改].[删除]按钮可用,[保存]按钮禁用 (2)点击[新增]按钮,[修改],[删除]按钮禁用,[保存]按钮启用 (3)点击[修改]按钮,[新增],[删除]按钮禁用 难点:通用数据库操作类中insert方法跟update方法 最终效果图: 前端功能不是很完善,按钮之间逻辑还是有点问题,最后补充前端代码 其中Formain.php对前端传值判断,并调用ac

PHP实现的一个简单的数据库操作类

PHP实现的一个简单的数据库操作类 实现的功能: - 在实例化的时候能设置连接字符集 - 在实例化的时候能连接数据库 - 在实例化的时候能选择默认数据库 - 销毁对象时关闭数据库 代码如下: <?php // 数据库操作类MySQLDB class MySQLDB { // 声明属性 private $server; private $username; private $password; public $default_db; public $link; // 声明构造函数 public f

php数据库操作类

话不多说,直接上代码! model.php 这里面为PHP的数据库操作类. 1 <?php 2 $config = include 'config.php'; 3 $m = new Model($config); 4 // $m->limit('0,5') 5 // ->table('imooc_cate') 6 // ->field('id,cName') 7 // ->order('id desc') 8 // ->where('id>3') 9 // -&g

PDO数据库操作类

1 <?php 2 include 'common_config.php'; 3 4 /** 5 * Class Mysql 6 * PDO数据库操作类 7 */ 8 class Mysql { 9 protected static $_dbh = null; //静态属性,所有数据库实例共用,避免重复连接数据库 10 protected $_dbType = DB_TYPE; 11 protected $_pconnect = false; //是否使用长连接 12 protected $_h

面向对象中数据库操作类

具体实现功能: 1.连接数据库: 2.插入数据: 3.更新数据: 4.删除数据' 5.修改数据: 6.求最大值: 7.求最小值: 8.求平均数: 9.求和: 10.指定查询: 具体代码分为三个部分: 一.config文件:主要用于连接数据库 <?php return array( 'DB_HOST' => '127.0.0.1',   //主机 'DB_USER' => 'root', //用户名 'DB_PWD' => '123456', //密码 'DB_NAME' =>