博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SqliteHelper整理(转载)
阅读量:6439 次
发布时间:2019-06-23

本文共 3876 字,大约阅读时间需要 12 分钟。

转载于

 

下面是全部代码:

class SqliteHelper     {    
       private string connStr = "";   
      public SqliteHelper(string dbName, bool isFullPath)  
       {           
  if (isFullPath)    
            {          
       connStr = @"Data Source=" + dbName + ";Initial Catalog=sqlite;Integrated Security=True;Max Pool Size=10";             }             else             {                 connStr = @"Data Source=" + System.Environment.CurrentDirectory + "\\" + dbName + ";Initial Catalog=sqlite;Integrated Security=True;Max Pool Size=10";             }         }         ///         /// 功能: 创建数据库,带路径         /// [2011-10-24 14:16 Bee]
    
    ///         ///        public void CreateDB(string dbName, bool isFullPath)         {             if (isFullPath)             {                 if (!File.Exists(dbName))                 {                     SQLiteConnection.CreateFile(dbName);                 }             }             else             {                 if (!File.Exists(System.Environment.CurrentDirectory + "\\" + dbName))                 {                     SQLiteConnection.CreateFile(System.Environment.CurrentDirectory + "\\" + dbName);                 }             }         }         ///         /// 功能: 执行sql,不返回         /// [2011-10-24 14:15 Bee]
        ///
        ///要执行的sql        public void ExecuteSql(string sqlStr)         {             using (DbConnection conn = new SQLiteConnection(connStr))             {                 conn.Open();                 DbCommand comm = conn.CreateCommand();                 comm.CommandText = sqlStr;                 comm.CommandType = CommandType.Text;                 comm.ExecuteNonQuery();             }         }         ///         /// 功能: 执行sql语句数组         /// [2011-10-24 14:54 Bee]
        ///
        ///        public void ExecuteSqlList(string[] sqlStr)         {             using (DbConnection conn = new SQLiteConnection(connStr))             {                 conn.Open();                 DbCommand comm = conn.CreateCommand();                 foreach (string item in sqlStr)                 {                     comm.CommandText = item;                     comm.CommandType = CommandType.Text;                     comm.ExecuteNonQuery();                 }             }         }         ///         /// 功能: 执行sql返回deteset         /// [2011-10-24 14:15 Bee]
        ///
        ///         ///
        public DataSet ExecDataSet(string sqlStr)         {             using (SQLiteConnection conn = new SQLiteConnection(connStr))             {                 conn.Open();                 SQLiteCommand cmd = conn.CreateCommand();                 cmd.CommandText = sqlStr;                 cmd.CommandType = CommandType.Text;                 SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);                 DataSet ds = new DataSet();                 da.Fill(ds);                 return ds;             }         }         ///         /// 功能: 判断表是否存在         /// [2011-10-24 14:14 Bee]
        ///
        ///         ///
存在不存在
        public bool IsTableExist(string tableName)         {             using (SQLiteConnection connection = new SQLiteConnection(connStr))             {                 connection.Open();                 using (SQLiteCommand command = new SQLiteCommand(connection))                 {
                    command.CommandText = "SELECT COUNT(*) FROM sqlite_master where type='table' and name='" + tableName + "'";                     int iaaa = Convert.ToInt32(command.ExecuteScalar());                     if (Convert.ToInt32(command.ExecuteScalar()) == 0)                     {                         return false;                     }                     else                     {                         return true;                     }                 }             }         }           }        
你可能感兴趣的文章
Android项目实战(二十九):酒店预定日期选择
查看>>
PHP IDE phpstorm 常用快捷键
查看>>
蓝牙的未来怎样发展?
查看>>
AI、新材料、5G、智慧城市,未来的社会场景在高交会提前上演
查看>>
Facebook开发的一种数据查询语言——GraphQL:安全概述和测试技巧
查看>>
ECS主动运维2.0,体验升级,事半功倍
查看>>
vim 学习方法
查看>>
php token验证范例
查看>>
WebSocket的C++服务器端实现
查看>>
java中两种添加监听器的策略
查看>>
脑洞成现实!AI系统可提前10s预测地震
查看>>
oracle数据库的启动和停止
查看>>
《LoadRunner没有告诉你的》之七——使用 LoadRunner 连续长时间执行测试,如何保证参数化的数据足够又不会重复?...
查看>>
python easy_install django 安装
查看>>
读《图解HTTP》总结--第六章
查看>>
毕业就能拿到上万薪资的程序员他们都做了啥?
查看>>
最小的k个数
查看>>
iOS技巧之获取本机通讯录中的内容,解析通讯录源代码
查看>>
程序员从零到月薪15K的转变,python200G资料分享
查看>>
DNS域名解析的知识了解
查看>>