Report don't display any data - reporting-services

I'm working on D365FO. I did create a report added a query to dataset that is based on a tmp table.
Now when I try to generate the report I get just the precisiondesign. No data is shown in it. How can I fix this ?
I think this is problem is somewhere outside of my code because I tried to generate a already created report and had the same problem.
[SrsReportParameterAttribute(classStr(ProductionStatusContract))]
class ProductionStatusDP extends SrsReportDataProviderBase
{
ProductionStatusTmp ProductionStatusTmp;
ProdTable prodtable;
SalesTable salestable;
InventDim inventdim;
SalesLine salesline;
public void processReport()
{
ProductionStatusContract contract = this.parmDataContract() as
ProductionStatusContract;
date FromDate;
date ToDate;
boolean DateBetween = false;
if(contract.parmToDate() && contract.parmFromDate())
{
ToDate = contract.parmToDate();
FromDate = contract.parmFromDate();
DateBetween = true;
}
super();
delete_from ProductionStatusTmp;
ProductionStatusTmp.clear();
while select prodtable where prodtable.CollectRefLevel == 0
join inventdim where prodtable.InventDimId == inventdim.inventDimId
join salesline where prodtable.InventRefType == salesline.InventRefType
&& prodtable.InventRefId == salesline.SalesId
&& prodtable.InventRefTransId == salesline.InventTransId
&& prodtable.InventRefType == inventreftype::Sales
{
ProductionStatusTmp.clear();
Info(strFmt("%1", prodtable.ProdId));
ProductionStatusTmp.AcceptedDate = prodtable.CreatedDateTime;
ProductionStatusTmp.ProdWeek = wkOfYr(prodtable.CreatedDateTime) + year(prodtable.CreatedDateTime);
ProductionStatusTmp.ExternalNum = salesline.ExternalItemId;
ProductionStatusTmp.Progress = ((prodtable.qtycalc * 100) / prodtable.QtySched);
ProductionStatusTmp.Quantity = prodtable.QtyCalc;
ProductionStatusTmp.AcceptedBy = prodtable.CreatedBy;
ProductionStatusTmp.ProdItemId = InventDim.InventLocationId;
ProductionStatusTmp.Ware = prodtable.Name;
ProductionStatusTmp.ProductionStatus = prodtable.ProdStatus;
ProductionStatusTmp.Produced = prodtable.QtySched;
ProductionStatusTmp.insert();
}
}
[SrsReportDataSetAttribute(tableStr(ProductionStatusTmp))]
public ProductionStatusTmp getProductionStatusTmp()
{
select ProductionStatusTmp;
return ProductionStatusTmp;
}
}

You will have to verify that your report does indeed display the data you provide.
You can do this by providing fixed static data in your data provider to see if shows up in the SSRS report preview.
See this video for an example to see how.

Related

In MVC, pass complex query and view model to session?

I have a view model:
public class UserCollectionView
{
public CardCollection CardCollections { get; set; }
public Card Cards { get; set; }
}
I have a List View Controller:
public ActionResult ViewCollection(int? page)
{
var userid = (int)WebSecurity.CurrentUserId;
var pageNumber = page ?? 1;
int pageSize = 5;
ViewBag.OnePageOfCards = pageNumber;
if (Session["CardCollection"] != null)
{
var paging = Session["CardCollection"].ToString.();
return View(paging.ToPagedList(pageNumber, pageSize));
}
var viewModel = from c in db.Cards
join j in db.CardCollections on c.CardID equals j.CardID
where (j.NumberofCopies > 0) && (j.UserID == userid)
orderby c.Title
select new UserCollectionView { Cards = c, CardCollections = j };
Session["CardCollection"] = viewModel;
return View(viewModel.ToPagedList(pageNumber, pageSize));
I am trying to use the PagedList to add paging to the results. I have been able to do this when I am not using a query that returns data from 2 databases in a single view. As shown here
My end result looks something like this:
Cards.SeveralColumns CardCollections.ColumnA CardCollections.ColumnB
Row 1 Data from Cards Table A from CardCollections B from CardCollections
Row 2 Data from Cards Table A from CardCollections B from CardCollections
Row 3 Data from Cards Table A from CardCollections B from CardCollections
And so on... I get an error
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
I have tried variations of SQL statements but can't get it to fit with my view model. In SQL Management Studio this brings back the correct results
Select * from Cards Inner Join CardCollections On Cards.CardID = CardCollections.CardID where CardCollections.UserID = 1 and CardCollections.NumberofCopies > 0;
I need a way to pass the query in session so the paging will operate correctly. Any advice is appreciated. :)
Short answer is, you can't. The model needs to be a snapshot of the content and therefore you can't pass an open query across the boundary (either as a hand-off to a session or to the client directly).
What you're seeing is the disposal of the context beyond it's initial use (where you assemble var viewmodel).
With that said, you can cache the results (to save overhead) if querying the data is an expensive operation. Basically, you'd store the entire collection (or at least a large subset of the collection) in the session/memorycache (which can then be manipulated into a paged list). Something to the effect of:
public ActionResult ViewCollection(int? page)
{
var userId = (int) WebSecurity.CurrentUserId;
var pageNumber = page ?? 1;
var pageSize = 5;
ViewBag.OnePageOfCards = pageNumber;
var cacheKey = String.Format("ViewCollection[{0}]", userId);
var entities = GetOrCreateCacheItem<IEnumerable<UserCollectionView>>(cacheKey, () => {
var query = (from c in db.Cards
join j in db.CardCollections on c.CardID equals j.CardID
where (j.NumberofCopies > 0) && (j.UserID == userid)
orderby c.Title
select new UserCollectionView { Cards = c, CardCollections = j }
)
.ToList(); // Force fetch from Db so we can cache
});
return View(entities.ToPagedList(pageNumber, pageSize));
}
// To give an example of a cache provider; Feel free to change this,
// abstract it out, etc.
private T GetOrCreateCacheItem<T>(string cacheKey, Func<T> getItem)
{
T cacheItem = MemoryCache.Default.Get(cacheKey) as T;
if (cacheItem == null)
{
cacheItem = getItem();
var cacheExpiry = DateTime.Now.AddMinutes(5);
MemoryCache.Default.Add(cacheKey, cacheItem, cacheExpiry);
}
return cacheItem;
}
It turns out that I didn't need to pass the query at all. If I let it run through it works fine without the session. I am not really sure why this works but my search query has to be passed. Maybe it is because I am using a viewmodel to perform the query. I will experiment and post if I find anything. Currently the working code is:
public ActionResult ViewCollection(int? page)
{
var userid = (int)WebSecurity.CurrentUserId;
var pageNumber = page ?? 1;
int pageSize = 5;
ViewBag.OnePageOfCards = pageNumber;
ViewBag.Rarity_ID = new SelectList(db.Rarities, "RarityID", "Title");
ViewBag.MainType_ID = new SelectList(db.MainTypes, "MainTypeID", "Title");
ViewBag.CardSet_ID = new SelectList(db.CardSets, "CardSetID", "Title");
ViewBag.SubType_ID = new SelectList(db.SubTypes, "SubTypeID", "Title");
var viewModel = from c in db.Cards
join j in db.CardCollections on c.CardID equals j.CardID
where (j.NumberofCopies > 0) && (j.UserID == userid)
orderby c.Title
select new UserCollectionView { Cards = c, CardCollections = j };
return View(viewModel.ToPagedList(pageNumber, pageSize));

query not displaying if another table has null value(sequence contains no elements)

I have a problem with the following code. It displays details if all tables have at least one value, but nothing if at least one table does not have a value. I get the message
sequence contains no elements.
My code as follow:
public sneakerDetails GetSneakerDetails(int id)
{
IQueryable<sneakerDetails> query = from sneaks in _context.sneakers
from image in _context.sneakerImages
from website in _context.sneakerWebsites
// from website in _context.sneakerWebsites
where sneaks.sneaker_id == id && image.sneaker_id == website.sneaker_id && sneaks.sneaker_id == website.sneake_id
select new sneakerDetails
{
//sneaker_id = sneaks.sneaker_id,
Colorway = sneaks.Colorway,
Name = sneaks.Name,
description = sneaks.description,
imageAlternative = image.imageAlternative,
release_date = sneaks.release_date,
imageB = image.imageB,
imageF = image.imageF,
imageL = image.imageL,
imageR = image.imageR,
website = website.website,
websiteLogo = website.websiteLogo
};
return query.ToList().First();
I have tried to change the return value to FirstOrDefault but when i click a particular sneaker it displays only the title and no data.
Do i need to write an if statement for both tables?
Try with DefaultIfEmpty():
from sneaks in _context.sneakers.DefaultIfEmpty()
from image in _context.sneakerImages.DefaultIfEmpty()
from website in _context.sneakerWebsites.DefaultIfEmpty()
// from website in _context.sneakerWebsites
where sneaks.sneaker_id == id
&& image.sneaker_id == website.sneaker_id
&& sneaks.sneaker_id == website.sneake_id
select new sneakerDetails
{
//sneaker_id = sneaks.sneaker_id,
Colorway = sneaks.Colorway,
Name = sneaks.Name,
description = sneaks.description,
imageAlternative = image.imageAlternative,
release_date = sneaks.release_date,
imageB = image.imageB,
imageF = image.imageF,
imageL = image.imageL,
imageR = image.imageR,
website = website.website,
websiteLogo = website.websiteLogo
};

Navigating Windows Phone 8 Pivot

While working on Windows Phone 8 app, we need to restrict user on navigating pivot.
For example, only first two items are available until user make his selection on second item, then third is unlocked, and so on.
I've tried several approaches, and all of them stumble on one thing - setting pivot.SelectedIndex (or pivot.SelectedItem) inside event handler does not changing visual representation of pivot.
What is missing in my approach?
Here is sample code, from one of variants I've tried...
private void ReservationPivot_UnloadingPivotItem(object sender, PivotItemEventArgs e)
{
if (previousSelectedIndex != ((Pivot)sender).Items.IndexOf(e.Item) && !pivotRedirect)
previousSelectedIndex = ((Pivot)sender).Items.IndexOf(e.Item);
else if (previousSelectedIndex == ((Pivot)sender).Items.IndexOf(e.Item))
return;
object tmp;
PhoneApplicationService.Current.State.TryGetValue("PickupAddress", out tmp);
if (e.Item == ((Pivot)sender).Items[1] && tmp == null && !pivotRedirect)
{
MessageBox.Show("Please, select pickup point!");
pivotRedirect = true;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
((Pivot)sender).SelectedItem = ((Pivot)sender).Items[1];
return;
}
PhoneApplicationService.Current.State.TryGetValue("DropOffAddress", out tmp);
if (e.Item == ((Pivot)sender).Items[2] && tmp == null && !pivotRedirect)
{
MessageBox.Show("Please, select dropoff point!");
pivotRedirect = true;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
((Pivot)sender).SelectedItem = ((Pivot)sender).Items[2];
return;
}
if (pivotRedirect)
{
if (((Pivot)sender).SelectedIndex != previousSelectedIndex)
{
pivotRedirect = false;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
}
}
}
Dont have access to visual now but did you try set visible of third pivot item to collapsed and change it to visible when user will select dropooff point ?

Auto manage and protect Created\Updated fields with Entity Framework 5

I want so every added\changed record will have a time stamp of creation\change.
But - so it will be easy to embed and easy to manage - automatically.
Overwrite the 'DbContext' class or embed this in the '.tt' file (Codefirst \ DBFirst)
The code assume so you have the fields 'CreatedOn'\'ModifiedOn' inside the POCO.
If you don't have them, or you have only one - the code will work fine.
Be aware! If you use a extension (as this one) so allow you to do batch updates or changes from a stored procedure - this will not work
EDIT:
I found the source of my inspiration - thanks 'Nick' here
public override int SaveChanges()
{
var context = ((IObjectContextAdapter)this).ObjectContext;
var currentTime = DateTime.Now;
var objectStateEntries = from v in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)
where v.IsRelationship == false && v.Entity != null
select v;
foreach (var entry in objectStateEntries)
{
var createdOnProp = entry.Entity.GetType().GetProperty("CreatedOn");
if (createdOnProp != null)
{
if (entry.State == EntityState.Added)
{
if (createdOnProp != null)
{
createdOnProp.SetValue(entry.Entity, currentTime);
}
}
else
{
Entry(entry.Entity).Property("CreatedOn").IsModified = false;
}
}
var modifiedOnProp = entry.Entity.GetType().GetProperty("ModifiedOn");
if (modifiedOnProp != null)
{
modifiedOnProp.SetValue(entry.Entity, currentTime);
}
}
return base.SaveChanges();
}

Linq-2-Sql code: Does this scale?

I'm just starting to use linq to sql. I'm hoping that someone can verify that linq-2-sql has deferred execution until the foreach loop is executed. Over all, can someone tell me if this code scales. It's a simple get method with a few search parameters. Thanks!
Code:
public static IList<Content> GetContent(int contentTypeID, int feedID, DateTime? date, string text)
{
List<Content> contentList = new List<Content>();
using (DataContext db = new DataContext())
{
var contentTypes = db.ytv_ContentTypes.Where(p => contentTypeID == -1 || p.ContentTypeID == contentTypeID);
var feeds = db.ytv_Feeds.Where(p => p.FeedID == -1 || p.FeedID == feedID);
var targetFeeds = from f in feeds
join c in contentTypes on f.ContentTypeID equals c.ContentTypeID
select new { FeedID = f.FeedID, ContentType = f.ContentTypeID };
var content = from t in targetFeeds
join c in db.ytv_Contents on t.FeedID equals c.FeedID
select new { Content = c, ContentTypeID = t.ContentType };
if (String.IsNullOrEmpty(text))
{
content = content.Where(p => p.Content.Name.Contains(text) || p.Content.Description.Contains(text));
}
if (date != null)
{
DateTime dateTemp = Convert.ToDateTime(date);
content = content.Where(p => p.Content.StartDate <= dateTemp && p.Content.EndDate >= dateTemp);
}
//Execution has been defered to this point, correct?
foreach (var c in content)
{
Content item = new Content()
{
ContentID = c.Content.ContentID,
Name = c.Content.Name,
Description = c.Content.Description,
StartDate = c.Content.StartDate,
EndDate = c.Content.EndDate,
ContentTypeID = c.ContentTypeID,
FeedID = c.Content.FeedID,
PreviewHtml = c.Content.PreviewHTML,
SerializedCustomXMLProperties = c.Content.CustomProperties
};
contentList.Add(item);
}
}
//TODO
return contentList;
}
Depends on what you mean with 'scales'. DB side this code has the potential of causing trouble if you are dealing with large tables; SQL Server's optimizer is really poor at handling the "or" operator in where clause predicates and tend to fall back to table scans if there are multiple of them. I'd go for a couple of .Union calls instead to avoid the possibility that SQL falls back to table scans just because of the ||'s.
If you can share more details about the underlying tables and the data in them, it will be easier to give a more detailed answer...