Visit our SharePoint Forum

SharePoint developer? Submit Yourself as Freelancer

Showing posts with label SP Query. Show all posts
Showing posts with label SP Query. Show all posts

Monday, March 31, 2008

SPQuery Examples


All SPQuery examples


Query for Date type Column in SharePoint


The above query is to find the items which has Date column with value less than Today's Date. The results will be returned in a Descending manner so you can get the most recently entered items from the List.

Query on Date Yes\No columns :


The Above query is to find the Item which has Current Date(i.e Today's Date) at "Date" column and a Yes at a checkbox column(Yes/No column).


For Detail SPQuery examples Goto :

All SPQuery examples

Tuesday, March 25, 2008

SPSiteDataQuery






SPSiteDataQuery Describes a query performed across multiple lists, which may be located in multiple Web sites in the same Web site collection.

You Can query multiple lists/Libraries of same kind for common fields in them. This Query returns a Datatable,which can be used as a source to a Calendar or GridView etc.

Query above will serach all the lists(Specified by Basetype = '0') for column name "EventDate" and value as Today's date. And returns Title , EventDate,Description,ListName(custom field in event List) in a form of a Table.


You can also Specify the List's to search in the scope! You need to provide the Guid of the List for that .

Wednesday, February 20, 2008

Using SPQuery with Yes/No Columns

To use Yes/No fields with SPQuery,You need to keep in mind some important things.

When you want to query the value for Yes/NO fields in SPQuery,
1. Use value type \"bit\" Not \"Text\
2. Use '1' for Yes & '0' for NO.

Note: Value type Text work fine with Yes/NO columns in MOSS 2007 but not in WSS.
So, If you are using WSS then you need to use bit not text.

Its always better to use CAML query builder to build a query, and then copy-paste that in SPQuery object.

To use Yes/No columns

if (Convert.ToBoolean(NewsItem["Publish?"]) == true)
{

}

Friday, February 15, 2008

A Tip for Writing SPQuery

To Use a SPQuery for getting the desired List data, We use Sharepoint's SPQuery class.

Some Important Notes about Using SPQuery.

* Use the Column Names that were kept Orignally when the Colum was made for the first time.(Not the ones that you see on column header,they may be same as they were kept earlier or may be not).

For eg, If you created a column with name "BName" and you changed the name(rename) to "BusinessName" later. You will have to use" BName" in SPQuery for getting the BusinessName column data Not "BusinessName".

More on SPQuery:

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spquery.aspx

SharePoint Programming