In my web part there is the following code, which should filter
list data --> but it doesn't !

SPWeb currentWeb =
Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
SPList list = currentWeb.Lists[SPEncode.HtmlEncode(listName)];

//without <query></query> it doesn't work --> error in web part
string caml = "<Query><Where><Eq><FieldRef Name='Vorname'></FieldRef><Value
Type='Text'>Patrick</Value></Eq></Where></Query>";

SPQuery query = new SPQuery();
query.Query = caml;
SPListItemCollection listItems = list.GetItems(query);

foreach (SPListItem listItem in listItems){...}

it shows all records, but should only show the filtered records!
can anybody help me ?
Patrick

RE: caml query problem by daniel

daniel
Thu Nov 18 17:21:05 CST 2004

Patrick,

You need to use the WSS internal name for the field name. Try this:
string internalName = list.Fields["Vorname"].InternalName;
...and use internalName in the query.

Daniel Larson
www.portalbuilder.org

"Patrick" wrote:

> In my web part there is the following code, which should filter
> list data --> but it doesn't !
>
> SPWeb currentWeb =
> Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
> SPList list = currentWeb.Lists[SPEncode.HtmlEncode(listName)];
>
> //without <query></query> it doesn't work --> error in web part
> string caml = "<Query><Where><Eq><FieldRef Name='Vorname'></FieldRef><Value
> Type='Text'>Patrick</Value></Eq></Where></Query>";
>
> SPQuery query = new SPQuery();
> query.Query = caml;
> SPListItemCollection listItems = list.GetItems(query);
>
> foreach (SPListItem listItem in listItems){...}
>
> it shows all records, but should only show the filtered records!
> can anybody help me ?
> Patrick
>
>

RE: caml query problem by Patrick

Patrick
Fri Nov 19 00:33:06 CST 2004

Thank you, now it works ! (without <query>...</query>)

Ciao,
Patrick

"Daniel Larson (www.portalbuilder.org)" wrote:

> Patrick,
>
> You need to use the WSS internal name for the field name. Try this:
> string internalName = list.Fields["Vorname"].InternalName;
> ...and use internalName in the query.
>
> Daniel Larson
> www.portalbuilder.org
>
> "Patrick" wrote:
>
> > In my web part there is the following code, which should filter
> > list data --> but it doesn't !
> >
> > SPWeb currentWeb =
> > Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
> > SPList list = currentWeb.Lists[SPEncode.HtmlEncode(listName)];
> >
> > //without <query></query> it doesn't work --> error in web part
> > string caml = "<Query><Where><Eq><FieldRef Name='Vorname'></FieldRef><Value
> > Type='Text'>Patrick</Value></Eq></Where></Query>";
> >
> > SPQuery query = new SPQuery();
> > query.Query = caml;
> > SPListItemCollection listItems = list.GetItems(query);
> >
> > foreach (SPListItem listItem in listItems){...}
> >
> > it shows all records, but should only show the filtered records!
> > can anybody help me ?
> > Patrick
> >
> >

RE: caml query problem by englantilainen

englantilainen
Fri Nov 19 01:15:03 CST 2004

Please in future post "programming" questions to the new subgroup for
programming questions ?

(microsoft.public.sharepoint.windowsservices.development

(Note to all: please don't post programming questions to both newsgroups)

Mike Walsh Helsinki
WSS FAQ wss.collutions.com


"Patrick" wrote:

> Thank you, now it works ! (without <query>...</query>)
>
> Ciao,
> Patrick
>
> "Daniel Larson (www.portalbuilder.org)" wrote:
>
> > Patrick,
> >
> > You need to use the WSS internal name for the field name. Try this:
> > string internalName = list.Fields["Vorname"].InternalName;
> > ...and use internalName in the query.
> >
> > Daniel Larson
> > www.portalbuilder.org
> >
> > "Patrick" wrote:
> >
> > > In my web part there is the following code, which should filter
> > > list data --> but it doesn't !
> > >
> > > SPWeb currentWeb =
> > > Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
> > > SPList list = currentWeb.Lists[SPEncode.HtmlEncode(listName)];
> > >
> > > //without <query></query> it doesn't work --> error in web part
> > > string caml = "<Query><Where><Eq><FieldRef Name='Vorname'></FieldRef><Value
> > > Type='Text'>Patrick</Value></Eq></Where></Query>";
> > >
> > > SPQuery query = new SPQuery();
> > > query.Query = caml;
> > > SPListItemCollection listItems = list.GetItems(query);
> > >
> > > foreach (SPListItem listItem in listItems){...}
> > >
> > > it shows all records, but should only show the filtered records!
> > > can anybody help me ?
> > > Patrick
> > >
> > >