zoukankan      html  css  js  c++  java
  • sqlite数据库查询批量

    采网页里的网址,网址每天都变化,而数据库里有几千条数据,通过 select count(*) 来查找数据库里有没有该网址,没有的话就采集入库,所 以如果网页当天更新1千条连接,那采集一次就要select count(*) 1千次, 1次select count(*) 要对比数据库里的几千条 数据,所以速度慢,请问像下面代码里 的 cmdlist.Add("update NewsAndNotice set ID = " + i + " where ID = " + newsID[i] + ";"); 的 方法,一次性把所有查询语句添到数组后,一次性查询,一次性反回每条查询后的结果!

                //string SQL = "select count(*) from News where SS= '网页地址'";
                //List<string> newsID = SQL_hp.Sql_Column(SQL);
    
                List<string> cmdlist = new List<string>();
                cmdlist.Add("BEGIN;");
                for (int i = 0; i < newsID.Count; i++)
                {
                    cmdlist.Add("update News set ID = " + i + " where ID = " + newsID[i] + ";");
                }
                cmdlist.Add("COMMIT;");
                SQL_hp.Sql_insert(cmdlist);
    
            public int Sql_insert(List<string> Cmd)
            {
                int tempint = 0;
                while (!ConnOpen())
                    Thread.Sleep(100);
                SQLiteCommand command = new SQLiteCommand("", conn);
                foreach (string i in Cmd.ToArray())
                {
                    command.CommandText = i;
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch { }
                }
                command.Dispose();
                ConnClose();
                return tempint;
            }
  • 相关阅读:
    form 编译命令
    Form文件夹开发步骤
    使用View为Data Source的Form开发要点
    spring2.0包说明【转】
    Zero to One读后感
    Fourth glance in Go
    Third glance in Go
    Second glance in Go
    First glance in Go
    MongoDB 安装
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4240726.html
Copyright © 2011-2022 走看看