Has anyone figured out how to use Crystal Reports with Linq to SQL?
Anyone that uses Crystal Reports or Crystal Server is bound to have a lengthy list of grievances. The product has an extremely high market share and continues to hold on to that market share, despite its limitations (a whopping 68% still). This is because Crystal Reports will get the job done.
Crystal Reports is a popular Windows-based report writer solution that allows a developer to create reports and dashboards from a variety of data sources with a minimum of code to write. Crystal Reports is owned and developed by SAP.
Crystal Reports can power pixel-perfect reporting for businesses. This solution enables organizations to combine analysis, business intelligence and decision support based on their data. The tool can analyze multiple data sources and then create visualizations of the data in charts and tables.
When you connect to an SQL database, Crystal Reports acts as an SQL client application, connecting to your SQL server through your network. When you design a report that accesses SQL data, Crystal Reports builds an SQL query. This query can be seen by choosing Show SQL Query from the Database menu.
You can convert your LINQ result set to a List
, you need not strictly use a DataSet
as the reports SetDataSource
, you can supply a Crystal Reports data with an IEnumerable
. Since List
inherits from IEnumerable
you can set your reports' Data Source to a List, you just have to call the .ToList()
method on your LINQ result set. Basically:
CrystalReport1 cr1 = new CrystalReport1();
var results = (from obj in context.tSamples
where obj.ID == 112
select new { obj.Name, obj.Model, obj.Producer }).ToList();
cr1.SetDataSource(results);
crystalReportsViewer1.ReportSource = cr1;
The msdn doc's suggest that you can bind a Crystal Report to an ICollection.
Might I recommend a List(T) ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With