using Newtonsoft.Json.Linq;
using System;
using System.Data.SQLite;
using System.IO;

namespace @public
{
    class Sqlite
    {
        public SQLiteConnection Sql;
        public SQLiteConnection open()
        {
            //数据库地址 字符串
            //这里将自己建立的数据文件的路径复制下来
            string FilePath = @"Data Source= C:\Users\appaudit\Desktop\public\2B8Y1JYHJ789_076627A55E2452F901212F1E7C84FD21.db";
            //new 数据库对象
            Sql = new SQLiteConnection(FilePath);
            //打开数据库
            Sql.Open();
            //返回数据库连接对象
            return Sql;
        }

        public SQLiteCommand command(string sql)
        {
            SQLiteCommand cmd = new SQLiteCommand(sql, open());
            return cmd;
        }

        public object Execute(string sql)  //查询操作
        {// select * from ludp_event order by id desc limit 1;
            return command(sql).ExecuteScalar();
        }

        public void SqlClose()
        {
            Sql.Close();//关闭数据库连接
        }
        static void Main(string[] args)
        {
            Console.ReadLine();
            Sqlite sql = new Sqlite();
            String obj = (string)sql.Execute("select event from ludp_event order by id desc limit 1");
            Console.WriteLine("category: " + obj.GetType());
            JObject jo = JObject.Parse(obj);
            Console.WriteLine("category: " + jo.GetType());
            Console.WriteLine("event_params " + jo["event_params"].ToString());
            Console.ReadLine();
            // 存到txt文件里
            FileStream fs = new FileStream(@"c:\Users\appaudit\Desktop\public\Writesmartkeyevent.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            try
            {
                sw.WriteLine(jo["event_params"][0]["value"]);
            }
            finally
            {
                if (sw != null) { 
                    sw.Close();
                    fs.Close();
                }
            }
            sql.SqlClose();
        }
    }
}

 

https://www.cnblogs.com/JiYF/p/11260178.html

用来进阶,我发布的时候还没看懂,留待以后

 posted on 2021-09-26 14:02  2165843  阅读(409)  评论(0)    收藏  举报