Some dataset fields don't appear on RDLC report - rdlc

I created dataset that contains Table View from SqlServer 2008 database.
Then I created a report (rdlc) and added the previous dataset as a source for this report.
In the code, I called a function that returns a list from My Table View type and assign this list to the created report as following:
ReportDataSource reportSource = new ReportDataSource();
reportSource.Name = "DataSet1";
reportSource.Value = GetData(); // returns List<MyTableViewType>
localReport.DataSources.Clear();
localReport.DataSources.Add(reportSource);
localReport.Refresh();
The problem is that I have three fields in the dataset don’t appear in the report although I am sure (By Debugging) that they got filled before rendering the report.
Any help will be appreciated ...
Thanks

You have to make sure that the dataFields name from your database is the same as declared in your report dataSource. Probably in the returned list the fields have different names.

if use the contractor
public xx(Model dbContext)
{
this.dbContext = dbContext;
}
replace with this
public xx()
{
this.dbContext = new Model();
}

Related

Retain Sort Order of Datagrid View after Updating SQL Adapter

As the title says, I am looking for a way to retain the sort order of my DataGridView after refreshing the data from SQL.
If I sort any of my columns, as soon as the data is refreshed, the columns are no longer sorted and the selected row I had is no longer selected.
Is there an easy solution that would be something along the lines of:
Dim NewSort as Something
SortOrder = DataGridView1
DataGridView1.Refresh
DataGridView1.SortOrder = NewSort
I know the above code is hypothetical but I would be pleased with any solution or to be pointed in the right direction. Google and Bing have not produced helpful resources.
I assume you have a sort, you do a database refresh and your sort is gone. I've encountered this before. I created an inherited grid to handle this, but there's the general idea.
Assuming you are binding to a DataView, consider this.
' Get the Sort
string currentSort = "";
if ( grid.DataSource != null )
currentSort = ((DataView) grid.DataSource).Sort
' Reset the Data Source
grid.DataSource = yournewsource of data ' Better Be a Data View
' Recall the Sort
((DataView) grid.DataSource).Sort = currentSort
One thing I did was had an inherited grid where the data the DataSource Get property was overwritten to have this, and used the inherited grid throughout the application, rather than having to put this code everywhere. It's easy enough to change to an inherited grid if you are comfortable going into the Designer file and editing.
public class MyDataGridView : System.Windows.Forms.DataGridView
{
public object DataSource
{
get
{
return base.DataSource;
}
set
{
string currentSort = "";
if (!(base.DataSource == null))
currentSort = ((DataView)base.DataSource).Sort;
base.DataSource = value;
((DataView)base.DataSource).Sort = currentSort;
}
}
}

How do I add a lazy loaded column in EntitySpaces?

If you do not have experience with or aren't currently using EntitySpaces ("ES") ORM this question is not meant for you.
I have a 10 year old application that after 4 years now needs my attention. My application uses a now defunct ORM called EntitySpaces and I'm hoping if you're reading this you have experience or maybe still use it too! Switching to another ORM is not an option at this time so I need to find a way to make this work.
Between the time I last actively worked on my application and now (ES Version 2012-09-30), EntitySpaces ("ES") has gone through a significant change in the underlying ADO.net back-end. The scenario that I'm seeking help on is when an entity collection is loaded with only a subset of the columns:
_products = new ProductCollection();
_products.Query.SelectAllExcept(_products.Query.ImageData);
_products.LoadAll();
I then override the properties that weren't loaded in the initial select so that I may lazyload them in the accessor. Here is an example of one such lazy-loaded property that used to work perfectly.
public override byte[] ImageData
{
get
{
bool rowIsDirty = base.es.RowState != DataRowState.Unchanged;
// Check if we have loaded the blob data
if(base.Row.Table != null && base.Row.Table.Columns.Contains(ProductMetadata.ColumnNames.ImageData) == false)
{
// add the column before we can save data to the entity
this.Row.Table.Columns.Add(ProductMetadata.ColumnNames.ImageData, typeof(byte[]));
}
if(base.Row[ProductMetadata.ColumnNames.ImageData] is System.DBNull)
{
// Need to load the data
Product product = new Product();
product.Query.Select(product.Query.ImageData).Where(product.Query.ProductID == base.ProductID);
if(product.Query.Load())
{
if (product.Row[ProductMetadata.ColumnNames.ImageData] is System.DBNull == false)
{
base.ImageData = product.ImageData;
if (rowIsDirty == false)
{
base.AcceptChanges();
}
}
}
}
return base.ImageData;
}
set
{
base.ImageData = value;
}
}
The interesting part is where I add the column to the underlying DataTable DataColumn collection:
this.Row.Table.Columns.Add(ProductMetadata.ColumnNames.ImageData, typeof(byte[]));
I had to comment out all the ADO.net related stuff from that accessor when I updated to the current (and open source) edition of ES (version 2012-09-30). That means that the "ImageData" column isn't properly configured and when I change it's data and attempt to save the entity I receive the following error:
Column 'ImageData' does not belong to table .
I've spent a few days looking through the ES source and experimenting and it appears that they no longer use a DataTable to back the entities, but instead are using a 'esSmartDictionary'.
My question is: Is there a known, supported way to accomplish the same lazy loaded behavior that used to work in the new version of ES? Where I can update a property (i.e. column) that wasn't included in the initial select by telling the ORM to add it to the entity backing store?
After analyzing how ES constructs the DataTable that is uses for updates it became clear that columns not included in the initial select (i.e. load) operation needed to be added to the esEntityCollectionBase.SelectedColumns dictionary. I added the following method to handle this.
/// <summary>
/// Appends the specified column to the SelectedColumns dictionary. The selected columns collection is
/// important as it serves as the basis for DataTable creation when updating an entity collection. If you've
/// lazy loaded a column (i.e. it wasn't included in the initial select) it will not be automatically
/// included in the selected columns collection. If you want to update the collection including the lazy
/// loaded column you need to use this method to add the column to the Select Columns list.
/// </summary>
/// <param name="columnName">The lazy loaded column name. Note: Use the {yourentityname}Metadata.ColumnNames
/// class to access the column names.</param>
public void AddLazyLoadedColumn(string columnName)
{
if(this.selectedColumns == null)
{
throw new Exception(
"You can only append a lazy-loaded Column to a partially selected entity collection");
}
if (this.selectedColumns.ContainsKey(columnName))
{
return;
}
else
{
// Using the count because I can't determine what the value is supposed to be or how it's used. From
// I can tell it's just the number of the column as it was selected: if 8 colums were selected the
// value would be 1 through 8 - ??
int columnValue = selectedColumns.Count;
this.selectedColumns.Add(columnName, columnValue);
}
}
You would use this method like this:
public override System.Byte[] ImageData
{
get
{
var collection = this.GetCollection();
if(collection != null)
{
collection.AddLazyLoadedColumn(ProductMetadata.ColumnNames.ImageData);
}
...
It's a shame that nobody is interested in the open source EntitySpaces. I'd be happy to work on it if I thought it had a future, but it doesn't appear so. :(
I'm still interested in any other approaches or insight from other users.

how do i create a dynamic view for data entry

What i want in the view is to spit out the fields that are part of the Department and Employee models depending on whichever one gets mentioned in the URL.
say for example department model has 5 fields
How do i create a view (dynamic/not strongly typed) that automatically displays the fields based on the model and let the user enter the values?
[HttpGet]
public ActionResult Create(string process)
{
if (process.Equals("Department"))
{
var model = new Department();
return View(model);
}
else if (process.Equals("Employee"))
{
var model = new Employee();
return View(model);
}
else
return View();
}
You can pass it as an object. You could also pass it in the viewdata (or viewbag). For both of these ways you would also need to include a flag so you know which one you should cast to. Both of these ways in my opinion though are hokey and prone to problems.
Another way would be to create a view model that combines both models. I personally would try to keep them separate and use separate calls \ views for each, depending on the requirements.

Add parameter to Telerik report from codebehind using mvc 4

I am very new to Telerik Reporting as well as MVC. I am using Telerik Reporting Q1 2013 and MVC 4. I want to pass some info as parameter to report. I tried by sending parameter from code behind of report, but no use. It showing all record.
What I have done is
public partial class ImmunizationRpt : Telerik.Reporting.Report
{
public ImmunizationRpt()
{
InitializeComponent();
Telerik.Reporting.ReportParameter param = new ReportParameter();
param.Name = "PatientKey";
param.Type = ReportParameterType.Integer;
param.AllowBlank = false;
param.AllowNull = false;
param.Value = 1;
param.Visible = true;
this.Report.ReportParameters.Add(param);
//this.Report.ReportParameters.Add("PatientKey",ReportParameterType.Integer,1);
}
}
If the parameter is already defined in the report, you can access it through the collection.
this.Report.ReportParameters["PatientKey"].Value = 1;
thank you for reply! i have achived this as
my report was showing all records, because i hadn't set the report to filter the records based on the parameter value. To achieve that, first we need to add the new parameter from the code behind (as i did) and then we need to add a new filter as shown in the following code:
Telerik.Reporting.Filter filter1 = new Telerik.Reporting.Filter();
filter1.Expression = "=Fields.PatientKey";
filter1.Operator = Telerik.Reporting.FilterOperator.Equal;
filter1.Value = "=Parameters.PatientKey.Value";
report.Filters.Add(filter1);

Loading jqgrid from query with multiple joins

I am trying to load a sortable jqgrid 3.5 from a query with multiple joins in it and having much difficulty as I am a novice with both Linq and jqgrid. In order to allow for sorting I first was attempting to load it using dynamic SQL.
Since I am pulling columns from multiple tables I assume my return will be a class object which I will populate (or will it be a table). How can I return a IQueryable custom class object when using dynamic SQL with multiple .JOIN clauses. If this is impossible how do I return IQueryable data from a stored procedure call. It is easy to create dynamic SQL in the stored procedure - I am unsure how to load my grid with it however.
Sorry if this is all over the place but I can't seem to find a way. If you can recommend the most straight forward way to load my sortable grid from a query which has multiple joins in I am much appreciated.
My controller code:
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
EquipTrak eqt = new EquipTrak();
var equipment = eqt.GetGridEquipment(sidx, sord);
var dataJson = new
{
total = 10000,
page = 1,
records = 10000,
rows = (from e in equipment
select new
{
equip_id = e.equip_id,
cell = new string[] {
e.equip_id,
e.equipType,
e.makeType,
String.Format("{0:MM/dd/yyyy}", e.serv_due_dt)
}
}).ToArray()
};
return Json(dataJson);
}
}
my class code (incomplete):
namespace ULS_Site.Models
{
public class EquipTrak
{
uls_dbDataContext ulsDB = new uls_dbDataContext();
public IQueryable<equipmentCls> GetGridEquipment(string sidx, string sord)
{
try
{
return
Not sure if this is the best or worst solution but I used SQL Server views to handle all the joining required. I could then use .Orderby and .Where against the view which was in my data context.