Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

How retrieve data/items from multiple sharepoint list?

$
0
0

I having two lists for example student list and mark list. in student list i have name, class, section, address and in mark list, i have science, mathematics, geografi. In Mark list there is lookup column that reference to studentid in student list. The result of this query is gridview with information from two list. for example name, class, mathematics and geografi. i have try by using caml query but it throw some exception.

<nativehr>0x80070057</nativehr><nativestack></nativestack> 

i try comment out query.projectedfields, the gridview is showing only studentid, mathematics and geografi. The information about name and adrdress is not showing. Is there something wrong with my query.projectedfields

SPQuery query = new SPQuery();

SPList customerList = Oweb.Lists["MarksMaster"];

query.Query = @"<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>null</Value></Neq></Where></Query>";

query.Joins = "<Join Type='Left' ListAlias='StudentMaster'>" +
                      "<Eq>" +
                      "<FieldRef Name='StudentID' RefType='ID'/>" +
                      "<FieldRef List='StudentMaster' Name='ID'/>" +
                      "</Eq>" +
                      "</Join>";

query.ProjectedFields = "<field Name='Name' Type='Lookup' List='StudentMaster' ShowField='Name'/>"+"<field                        Name='Address' Type='Lookup' List='StudentMaster' ShowField='Address'/>";

query.ViewFields = "<FieldRef Name='Section'/>" +
                        "<FieldRef Name='ScienceGroup'/>";

SPListItemCollection itemCollection = customerList.GetItems(query);

int fieldCount = itemCollection.Fields.Count;
var items = itemCollection.GetDataTable();

gvCollated.DataSource = items;
gvCollated.DataBind();   

Can somebody help me.


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>