提高foreach 更新 效率 更新数据库一批数据 但每次更新前都要查询一下
查询后 更新 条码关系
codelist=‘1’,‘2’,‘3’,‘4’,‘5’ 之类的
Bbarcode =‘xxxxxx’
foreach (string s in codelist)
{
string sql = "SELECT * FROM BarCode where sbarcode ='" + Sbarcode + "' and bbarcode is null and isuse=0";
Tb_BarCode barcode = db.SqlQuery<Tb_BarCode>(sql).FirstOrDefault();
if (barcode != null)
{
string sql2 = "update BarCode set BBarCode='" + Bbarcode + "' where sbarcode ='" + Sbarcode + "' and bbarcode is null and isuse=0";
if (result.IndexOf(Bbarcode) == -1)
{
result = result + Bbarcode + ",该大码成功绑定以下小码\r\n--------------------\r\n";
}
if (db.ExecuteSqlCommand(sql2) > 0)
{
result = result + Sbarcode + ",绑定成功!\r\n";
}
else
{
result = result + Sbarcode + ",绑定失败!\r\n";
}
}
else
{
if (result.IndexOf(Bbarcode) == -1)
{
result = result + Bbarcode + "\r\n--------------------\r\n";
}
result = result + Sbarcode + ",该码已绑定!\r\n";
} }