public DataTable BindSPData(string txtSPNumber,
string txtTitle, string strOriginator)
{
WindowsIdentity objWindowsIdentity = WindowsIdentity.GetCurrent();
WindowsImpersonationContext objWindowsImpersonationContext = null;
RevertToSelf();
SPQuery oquery = null;
SPSite siteCollection = null;
SPWeb topLevelSite = null;
SPListItemCollection myitems = null;
try
{
objWindowsImpersonationContext = WindowsIdentity.GetCurrent().Impersonate();
siteCollection = new SPSite(System.Configuration.
ConfigurationManager.AppSettings["SPSPSite"]);
topLevelSite = siteCollection.AllWebs[System.Configuration.
ConfigurationManager.AppSettings["SPTopLevelSite"]];
SPList list = topLevelSite.Lists[System.Configuration.
ConfigurationManager.AppSettings["SPListName"]];
topLevelSite.AllowUnsafeUpdates = true;
//Create an instance of SPQuery Object
oquery = new SPQuery();
if (((txtSPNumber != “”) & (txtTitle != “”)) ||
((txtTitle != “”) & (strOriginator != “”)) || ((strOriginator != “”) &
(txtSPNumber != “”)))
{
oquery.Query = “”;
}
else
{
if ((txtSPNumber != “”) || (txtTitle != “”) || (strOriginator != “”))
{
oquery.Query = “”;
}
}
if (txtSPNumber != “”)
{
oquery.Query += “” + txtSPNumber + “”;
}
if (txtTitle != “”)
{
oquery.Query += “” + txtTitle + “”;
}
if (strOriginator != “”)
{
oquery.Query += “” + strOriginator + “”;
}
if (((txtSPNumber != “”) & (txtTitle != “”)) || ((txtTitle != “”) &
(strOriginator != “”)) || ((strOriginator != “”) & (txtSPNumber != “”)))
{
oquery.Query += “”;
}
else
{
if ((txtSPNumber != “”) || (txtTitle != “”) || (strOriginator != “”))
{
oquery.Query += “”;
}
}
DataTable dtNewItems;
//Assign the query object to myitems List Collection
if ((oquery.Query != “”) & (oquery.Query != null))
{
myitems = list.GetItems(oquery);
dtNewItems = myitems.GetDataTable();
}
else
{
myitems = list.Items;
//Get the Datatable for ALL the list items
dtNewItems = myitems.GetDataTable();
}
return dtNewItems;
}
catch (Exception ex)
{
throw ex;
}
finally
{
objWindowsImpersonationContext.Undo();
topLevelSite.AllowUnsafeUpdates = false;
siteCollection.Dispose();
topLevelSite.Dispose();
}
}
—————————————–
SPQuery query = new SPQuery();
query.Query = “10?;
SPQuery query = new SPQuery();
query.Query = “10?;