The query in your code is searching for items where field named Hidden
has value set to TRUE
. My guess is that your list doesn't have field named Hidden
.
I will answer your question with some code:
//Always make sure you dispose SPSite and SPWeb objects
using (SPSite site = new SPSite("http://mycoolsite"))
{
using(SPWeb web = site.OpenWeb())
{
const string tmpField = "<FieldRef Name='{0}'/>";
string viewFields = string.Empty;
SPList myList = web.Lists["myCoolListName"];
//Get all list fields
var listFields = myList.Fields;
//Build View Fields
foreach (SPField listField in listFields)
{
//Only add if field is not hidden
if(!listField.Hidden)
viewFields += string.Format(tmpField, listField.InternalName);
}
SPQuery query = new SPQuery();
query.Query = ""; // You can add some condition. Items returned by query
query.ViewFields = viewFields; //Fields returned by query
DataTable dtListSource = myList.GetItems(query).GetDataTable();
}
}
Some more info on MSDN: SPQuery.ViewFields