標籤:
采網頁裡的網址,網址每天都變化,而資料庫裡有幾千條資料,通過 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; }
sqlite資料庫查詢批量