Detect Duplicate Item with same properties before updating an existing record
The following c# code detects duplicate item with same same properties before updateing
an existing record.
category = "General";
subcategory = "General";
type = "General";
id = 1;
var check = (from i in db.TableName
where i.Category.Equals(category ,StringComparison.OrdinalIgnoreCase)
&& i.SubCategory.Equals(subcategory ,StringComparison.OrdinalIgnoreCase)
&& i.Type.Equals(type ,StringComparison.OrdinalIgnoreCase)
&& i.ID != id_
select i).FirstOrDefault();
if (check != null)
{
MessageBox.Show("Duplicate Item detected with following properties."
+ Environment.NewLine + "Category " + category
+ Environment.NewLine + "Subcategory " + subcategory
+ Environment.NewLine + "Type " + type
"Attention!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
code to continue the process
}
For further question please mail: brainstormiert@gmail.com