0

How can compare one item list with others items list in the meaning of No duplicate values ??

if (item.Title != dp1.Text + tb2.Text)
                        {
                        item["Title"] = dp1.Text + tb2.Text;
                        item["Nom"] = nom;
                        //item1["Date"] = DateTime.Now;
                        item["Qualification"] = qul;
                        item["Sit.Fam"] = sf;
                        item.Update();    
                            }
                            else
                            {
                                Console.WriteLine("Bulletin déja créer");  
                            }
0

I would suggest to use CAML query with Equal statement with your possible string concatenations that meets the requirement.

more details can be found in the below article and it's not a good practice to loop each item to compare.

https://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx

0

Update your code as below,

    SPQuery myquery = new SPQuery();
        myquery.Query = "<Where>" +                       
                        "<Eq>"+
                        "<FieldRef Name='Title' />"+
                        "<Value Type='Text'>"+
                         dp1.Text + tb2.Text  +
                        "</Value>" +
                        "</Eq>" +                             
                        "</Where>";
      SPListItemCollection items = list.GetItems(myquery);
    If(items.count > 0)
    {
                            item["Title"] = dp1.Text + tb2.Text;
                            item["Nom"] = nom;
                            //item1["Date"] = DateTime.Now;
                            item["Qualification"] = qul;
                            item["Sit.Fam"] = sf;
                            item.Update();
    }
   else
                            {
                                Console.WriteLine("Bulletin déja créer");  
                            }
1
  • I want to test the existence of an item before adding it
    – faten
    May 31 '17 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.