Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm charging my spquery with different parameters from a static class called Fields : In fact I'm using this query to bind result data to my asp:grid view

using (SPSite mySite = new SPSite(SPContext.Current.Web.Site.Url))
{
    SPListItemCollection collListItemsDT = getAllCorrListItemsforCT();
            DataTable GVdataSource = new DataTable();
            GVdataSource.Columns.Add("Titre", typeof(string));
            foreach (SPListItem myListItem in collListItemsDT)
            {
                DataRow myTypeValueOrderRow = GVdataSource.NewRow();
                myTypeValueOrderRow["Titre"] = myListItem["Title"].ToString();
                GVdataSource.Rows.Add(myTypeValueOrderRow);
            }
            TypeValueOrderGV.DataSource = GVdataSource;
            TypeValueOrderGV.DataBind();
    }

and the fonction providing the items from my query :

    protected SPListItemCollection getAllCorrListItemsforCT()
    {
        SPList corrList = getSelectedList("Correspondance");
            if (corrList != null)
            {
                SPQuery myQuery = new SPQuery();
                myQuery.Query = "<Where><And><Eq><FieldRef Name=\"Title\"/>" +
                   "<Value Type=\"Text\">Document interne</Value></Eq><Eq><FieldRef Name=\"Fonction\"/>" +
                   "<Value Type=\"Text\">GenerateChrono</Value></Eq></And></Where>";
                SPListItemCollection allCorrListItems = corrList.GetItems(myQuery);
                Label_Hello.Text += "Hi | " + allCorrListItems[1].Fields[1].ToString();
                return allCorrListItems;
            }
            return null;
    }
     public SPList getSelectedList(string ListTitle)
    {
        using (SPSite mySite = new SPSite(SPContext.Current.Web.Site.Url))
        {
            SPWebCollection myWebs = mySite.AllWebs;
            foreach (SPWeb myWeb in myWebs)
            {
                using (myWeb)
                {
                    SPListCollection myLists = myWeb.Lists;
                    foreach (SPList myList in myLists)
                    {
                        if (myList.Title.Equals(ListTitle))
                            return myList;
                    }
                }
            }
            return null;
        }
    }

and my label gives me this :

|| querystr GenerateChronoDocument interne ||

which are Fields.GenerateChronoFnTitre string and contentTypeName vriable value ! I tried to fix this other way :

querystr = string.Format("<Where><And><Eq><FieldRef Name='{0}' /><Value Type='Text'>{1}</Value></Eq>"+
    "<Eq><FieldRef Name='{2}'/><Value Type='Text'>{3}</Value></Eq></And></Where>",
    FonctionIN, GenerateChronoTitre,TitreIN, contentTypeName);

and it gave me the exact same result !!! so what should I do to make my query get charged correctly !!

Just for the record I used to have this error and I tried to escape :

Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before.

share|improve this question
    
Glolita, this should work.. are you assigning any other values to querystr? Please give complete code! –  Arsalan Adam Khatri Nov 6 '12 at 9:36
    
no I've checked everything and still doesn't work ! –  Glolita Nov 6 '12 at 9:40
1  
Glolita, provide more code to help! –  Arsalan Adam Khatri Nov 6 '12 at 10:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.