Get DataTable from the list
public static System.Data.DataTable GetListData(string strListName, string strViewFields, string strQuery)
{
try
{
SPWeb oWeb = SPContext.Current.Web;
SPListItemCollection items = null;
string strListURL = oWeb.Url + "/Lists/" + strListName;
SPList oList = oWeb.GetList(strListURL);
SPQuery oQuery = new SPQuery();
oQuery.ViewFields = strViewFields;
oQuery.Query = strQuery;
items = oList.GetItems(oQuery);
if (items.Count > 0)
return items.GetDataTable();
else
return null;
}
catch (Exception ex)
{
return null;
}
}
Get SPListItem from the list
public static SPListItem GetListItem(string strListName, string strViewFields, string strQuery)
{
try
{
SPWeb oWeb = SPContext.Current.Web;
SPListItemCollection items = null;
string strListURL = oWeb.Url + "/Lists/" + strListName;
SPList oList = oWeb.GetList(strListURL);
SPQuery oQuery = new SPQuery();
oQuery.ViewFields = strViewFields;
oQuery.Query = strQuery;
oQuery.RowLimit = 1;
items = oList.GetItems(oQuery);
if (items.Count > 0)
return items[0];
else
return null;
}
catch (Exception ex)
{
return null;
}
}
public static System.Data.DataTable GetListData(string strListName, string strViewFields, string strQuery)
{
try
{
SPWeb oWeb = SPContext.Current.Web;
SPListItemCollection items = null;
string strListURL = oWeb.Url + "/Lists/" + strListName;
SPList oList = oWeb.GetList(strListURL);
SPQuery oQuery = new SPQuery();
oQuery.ViewFields = strViewFields;
oQuery.Query = strQuery;
items = oList.GetItems(oQuery);
if (items.Count > 0)
return items.GetDataTable();
else
return null;
}
catch (Exception ex)
{
return null;
}
}
Get SPListItem from the list
public static SPListItem GetListItem(string strListName, string strViewFields, string strQuery)
{
try
{
SPWeb oWeb = SPContext.Current.Web;
SPListItemCollection items = null;
string strListURL = oWeb.Url + "/Lists/" + strListName;
SPList oList = oWeb.GetList(strListURL);
SPQuery oQuery = new SPQuery();
oQuery.ViewFields = strViewFields;
oQuery.Query = strQuery;
oQuery.RowLimit = 1;
items = oList.GetItems(oQuery);
if (items.Count > 0)
return items[0];
else
return null;
}
catch (Exception ex)
{
return null;
}
}
No comments:
Post a Comment