【sqlite】VS2013中C#读取SQLite数据

       从“火车采集器”(免费版)中获取的网页数据,本地只能自动保存为SQLite数据,(在工具-数据转换中切换)。收费版还可以用MySql、SqlServer

今天就记录一下C#读取Sqlite数据

创建一个控制台应用程序SqliteTest,项目右键—管理NuGet程序包,搜索Sqlite,根据系统版本安装SQlite,我选择X64。

 

 static void Main(string[] args)
        {
            if (System.IO.File.Exists("D:\\my install\\火车采集器V9\\Data\\1\\SpiderResult.db3"))
            {
                SQLiteConnection cnn = new SQLiteConnection();
                cnn.ConnectionString = "Data Source=D:\\my install\\火车采集器V9\\Data\\1\\SpiderResult.db3";
                cnn.Open();

                string sql = "select * from Content"; //用SQLite Expert管理器看表或者CMD看
                SQLiteCommand cmd = cnn.CreateCommand();
                cmd.CommandText = sql;

                SQLiteDataReader reader = cmd.ExecuteReader();
                StringBuilder sb = new StringBuilder();
                int count = 0;
                while (reader.Read())
                {
                    sb.Append("ID:").Append(reader.GetInt16(0)).Append("\n")
                    .Append("标题:").Append(reader.GetString(3)).Append("\n")
                    .Append("URI:").Append(reader.GetString(5)).Append("\n");
                    count++;
                }
                Console.WriteLine(sb);
                Console.WriteLine("总共数据个数:" + count);
            }
            else
            {
            }
            Console.Read();
        }

 

结果:

 

【sqlite】VS2013中C#读取SQLite数据_第1张图片



 

转载于:https://www.cnblogs.com/peterYong/p/6556537.html

你可能感兴趣的:(【sqlite】VS2013中C#读取SQLite数据)