Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have 2 lists one is Employee1(Title renamed as Ename & Contact as column) enter image description here

another is Projects(LookUp from Employee1 id field).

enter image description here

Now I want inner join between 2 lists.

I have written

class Program
{
    static void Main(string[] args)
    {
        using (SPSite site = new SPSite("http://10.141.16.33:10002/SitePages/Home.aspx"))
        {
            SPWeb web=site.OpenWeb();

            SPQuery query = new SPQuery();
            query.Joins = "<Join Type='INNER' ListAlias='Employee1'>" +
                "<Eq>" +
                    "<FieldRef Name='Manager' RefType='Id'/>" +
                    "<FieldRef List='Employee1' Name='ID'/>" +
                "</Eq>" +
                "</Join>";
            query.ProjectedFields = "<Field Name='Employee1Ename' Type='Lookup' " +
            "List='Employee1' ShowField='Title'/>" +
            "<Field Name='Employee1Contact' Type='Lookup' " +
            "List='Employee1' ShowField='Contact'/>";

            query.ViewFields = "<FieldRef Name='Title'/>" +
                    "<FieldRef Name='Employee1Ename'/>" +
                    "<FieldRef Name='Employee1Contact'/>";

            SPList list = web.Lists["Projects"];
            SPListItemCollection coll = list.GetItems(query);
            foreach (SPListItem item in coll)
            {
                SPFieldLookupValue Ename = new SPFieldLookupValue(item["Employee1Ename"].ToString());
                SPFieldLookupValue contact = new SPFieldLookupValue(item["Employee1Contact"].ToString());

                Console.WriteLine("{0}  {1}   {2}", item.Title, Ename.LookupValue, contact.LookupValue);
            }
            Console.ReadKey();
        }
    }
}

But when I run I get following error. enter image description here

I am not able to find out why.Please help.thanks.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

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.