2,209
社区成员
发帖
与我相关
我的任务
分享
#region //提取搜索结果中的宝贝链接
private void getlinks(object workmode)
{
...................省略部分代码
//写入数据库
try
{
SQLiteConnection mycon = new SQLiteConnection();
SQLiteConnectionStringBuilder connsb = new SQLiteConnectionStringBuilder();
connsb.DataSource = dbName;
mycon.ConnectionString = connsb.ToString();
mycon.Open();
for (int i = 0; i < itemlinks.Count; i++)
{
SQLiteCommand mycmd = new SQLiteCommand();
switch (workmode.ToString())
{
case "a":
mycmd = new SQLiteCommand(string.Format("insert INTO itemdetails(itemid,checkedtime,itemurl) select '{0}','{1}','{2}' where not exists(select itemid,checkedtime from itemdetails where itemid='{0}'); ", getItemid(itemlinks[i]), checkedtime, itemlinks[i]), mycon);
mycmd.ExecuteNonQuery();
mycmd = new SQLiteCommand(string.Format("update itemdetails set zhrank={0} where itemid={1};", i + 1,getItemid(itemlinks[i])), mycon);
mycmd.ExecuteNonQuery();
break;
case "b":
mycmd = new SQLiteCommand(string.Format("insert INTO itemdetails(itemid,checkedtime,itemurl) select '{0}','{1}','{2}' where not exists(select itemid,checkedtime from itemdetails where itemid='{0}'); ", getItemid(itemlinks[i]), checkedtime, itemlinks[i]), mycon);
mycmd.ExecuteNonQuery();
mycmd = new SQLiteCommand(string.Format("update itemdetails set rqrank={0} where itemid={1};", i + 1, getItemid(itemlinks[i])), mycon);
mycmd.ExecuteNonQuery();
break;
case "c":
mycmd = new SQLiteCommand(string.Format("insert INTO itemdetails(itemid,checkedtime,itemurl) select '{0}','{1}','{2}' where not exists(select itemid,checkedtime from itemdetails where itemid='{0}'); ", getItemid(itemlinks[i]), checkedtime, itemlinks[i]), mycon);
mycmd.ExecuteNonQuery();
mycmd = new SQLiteCommand(string.Format("update itemdetails set xlrank={0} where itemid={1};", i + 1, getItemid(itemlinks[i])), mycon);
mycmd.ExecuteNonQuery();
break;
case "d":
mycmd = new SQLiteCommand(string.Format("insert INTO itemdetails(itemid,checkedtime,itemurl) select '{0}','{1}','{2}' where not exists(select itemid,checkedtime from itemdetails where itemid='{0}'); ", getItemid(itemlinks[i]), checkedtime, itemlinks[i]), mycon);
mycmd.ExecuteNonQuery();
mycmd = new SQLiteCommand(string.Format("update itemdetails set tmrank={0} where itemid={1};", i + 1, getItemid(itemlinks[i])), mycon);
mycmd.ExecuteNonQuery();
break;
}
}
mycon.Close(); //关闭数据库连接
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}