Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, December 05, 2011

Checking Duplicate Values within a list using SpQuery.

try
            {
                SPWeb curentWeb = SPControl.GetContextWeb(Context);
                SPList lst = curentWeb.Lists["Telno"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + txtFname.Text.ToString().ToLower() + "</Value></Eq></Where>";
                SPListItemCollection myColl = lst.GetItems(sQuery);
                if (myColl.Count > 0)
                {
                    strError += "<Script Language='JavaScript' type='JavaScript'>";
                    strError += "alert('Friend Name Already Available');";
                    strError += "</Script>";
                }
                else
                {
                    strError += "<Script Language='JavaScript' type='JavaScript'>";
                    strError += "alert('Friend Name Not Available');";
                    strError += "</Script>";
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }

No comments:

Post a Comment