public static int Update(string strJson) { int count = 0; List<Dictionary<string, object>> listRows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(strJson); foreach (var row in listRows) { var dic = row.ToDictionary(item => item, item => true); string strUpdateKey = ""; string strUpdateKeyValue = ""; StringBuilder sb_Set = new StringBuilder(""); foreach (var col in dic) { string strKey = col.Key.Key; string strValue = col.Key.Value.ToString(); // 用于where字段和值的保存 if (strKey == "KeyID") { strUpdateKey = strKey; strUpdateKeyValue = strValue; } if (strKey == "terminalWorkOrderProductionWeftinfoVoList") { continue; } if (sb_Set.ToString() == "") { sb_Set.Append(string.Format(strKey + "='{0}'", strValue)); } else { sb_Set.Append(string.Format(","+strKey + "='{0}'", strValue)); } } string strWhere = string.Format(" where {0} = '{1}';", strUpdateKey, strUpdateKeyValue); StringBuilder sb_Sql = new StringBuilder("update ProductPlan set "); sb_Sql.Append(sb_Set.ToString()); sb_Sql.Append(strWhere); count = count + SQLiteHelper.ExecuteNonQuery(sb_Sql.ToString()); } return count; }
标签:count,Set,string,C#,strValue,json,strKey,SQL,sb From: https://www.cnblogs.com/chengeng/p/17829009.html