-1
I tried everything, changed the codes, changed several things but the error prevails.
Code:
class Program
{
public static void Main(string[] args)
{
List<string> listaProcesso = new List<string>();
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=CORPORATE02;Initial Catalog=ANDAMENTOS;Persist Security Info=True;User ID=textractor;Password=jfkhuk";
con.Open();
SqlCommand cmd = new SqlCommand("select * from tbprocesso_teste where idcliente = 23915 and flag = 5", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
listaProcesso.Add(reader.GetString(21));
}
con.Close();
List<string> listaProcessoConcertados = new List<string>();
foreach (var elemento in listaProcesso)
{
var resultado = TratarErroJson(elemento);
listaProcessoConcertados.Add(resultado);
}
foreach(var elemento in listaProcessoConcertados)
{
UpdateJson(elemento);
}
}
public static string TratarErroJson(string jsonErrado)
{
var arquivo = jsonErrado;
int posicao = arquivo.IndexOf("itensProcesso");
int posicao1 = arquivo.IndexOf("mensagemErro");
if (posicao > -1)
{
string str = arquivo.Substring(0, posicao);
string obj = str + "itensProcesso\":[]}";
Console.WriteLine(obj);
return obj;
}else if (posicao1 > -1)
{
return jsonErrado;
}
else
{
return"";
}
}
public static void UpdateJson (object MyUpdate)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=CORPORATE02;Initial Catalog=ANDAMENTOS;Persist Security Info=True;User ID=textractor;Password=okmnji90";
con.Open();
string query = "update tbprocesso_teste set txdistribuicao=" + MyUpdate + " where idcliente = 23915 and flag = 5";
SqlCommand cmd = new SqlCommand(query);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
}