C#读sqlite数据库

 using System.Data.SQLite;//若没有库需要在Nugut下载

private void ReadDatabase()
        {
            //判断有无数据库
            if (!File.Exists(dbPath))
            {
                SQLiteConnection.CreateFile(dbPath);
                MessageBox.Show("数据库重新创建成功");
            }

            //判断有无表
            if (sqliteConn.State == ConnectionState.Closed) sqliteConn.Open();
            SQLiteCommand mDbCmd = sqliteConn.CreateCommand();
            mDbCmd.CommandText = "SELECT COUNT(*) FROM sqlite_master where type='table' and name='" + TableDbFile + "';";
            int row = Convert.ToInt32(mDbCmd.ExecuteScalar());
            if (row <= 0)
            {
                MessageBox.Show("数据表不存在,无法查询");
                return;
            }
          
            //读
            string firmName = "三星";
            mDbCmd.CommandText = "SELECT* FROM SOPFileTable WHERE firm ='" + firmName + "';";
            SQLiteDataReader reader = mDbCmd.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine("获取数值" + reader["file"].ToString());
            }
            reader.Close();
            sqliteConn.Close();
        }

相关推荐

  1. C#sqlite数据库

    2024-05-09 11:06:10       11 阅读
  2. C语言数据库Sqlite3基础介绍

    2024-05-09 11:06:10       12 阅读
  3. 基础Python教程之sqlite

    2024-05-09 11:06:10       46 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-09 11:06:10       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-09 11:06:10       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-09 11:06:10       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-09 11:06:10       20 阅读

热门阅读

  1. (二)JVM实战——jvm实战之运行时数据区详解

    2024-05-09 11:06:10       13 阅读
  2. vue3项目 文件组成

    2024-05-09 11:06:10       10 阅读
  3. 为什么C++11还要复杂的提出右值引用?

    2024-05-09 11:06:10       11 阅读
  4. C语言内存泄漏查找

    2024-05-09 11:06:10       10 阅读
  5. CentOS常见命令深度解析:从基础到进阶

    2024-05-09 11:06:10       13 阅读
  6. axios 取消token 模糊搜索

    2024-05-09 11:06:10       11 阅读
  7. 简单负载均衡

    2024-05-09 11:06:10       9 阅读