In my project I have a rule that does not save and does not show in Grid duplicate data. For example, on the system I read an XML and save the tags information to a table in my database so that this information is displayed in a Grid .
But every time I do this reading, the data is saved twice. I mean, if I've read it once and been saved, for example, the name 'John' in that first reading, if I read XML again, the name is saved again, and so on. how often do I read the XML .
So I made a logic so that I did not show the Grid this duplicate data, which is this:
if (Convert.ToString(GetValueOrDefault(elmCertidao.Element("nome_tag_1"))) == objeto.Propriedades["Coluna1"].Valor &&
Convert.ToString(GetValueOrDefault(elmCertidao.Element("nome_tag_2"))) == objeto.Propriedades["Coluna2"].Valor &&
Convert.ToString(GetValueOrDefault(elmCertidao.Element("nome_tag_3"))) == objeto.Propriedades["Coluna3"].Valor)
continue;
In other words, if there are data in these tags that are already in Grid , that data is not shown ...
So far beauty, but it turns out that duplicate data is saved in the database table, and that's not what I want.
I want you to not show in Grid and do not save duplicate data.
This question from SOpt give me an idea what to do. But if I put the fields as Unique , every time I read XML , and the inconsistency is checked, it will give error in SQL Server
saying that the data already exists .
Is there any way I can do this check and show no error, neither of SQL Server
nor C#
? That is, just saving the die once?