How to use object datasource in RDLC report in webapi2 - rdlc

In asp.net webapi2 after adding rdlc report When I want to create dataset then I could not find my object data source in wizard(I have found only database wizard.). But in asp.net I have found object datasource. Is there any way to use object datasource in webapi2 rdlc report.

Related

Dataset/datasource Winform VB project using ReportViewer

We are trying to figure out how the ReportViewer works and are stuck at the dataset/datasource part. We have a sql-query that connects with 3 different Servers. Is there a simple way to connect a rdlc report to such a dataset in a winform Project that will be shown in Report Viewer?
You have to add a ReportDataSource object to the LocalReport.DataSources Property. The constructor take two parameters.
First the name of the dataset (as it is defined in the rdlc repport), second a datasource object which could be any .Net Collection (ADO.Net DataSet or a simple List of object).
The mapping to the field declared is done in the same way than DataBinding. Just have the same name for the column of the ADO.Net DataSet or the property of the object in the list than the field in the report.
Take a look at
https://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.aspx

Unable to programatically reference subreport property (EnableExternalImages) from main report

I have what i think is a unique requirement not addressed in other questions. I've developed a local report in Microsoft report designer as an rdlc and am viewing it via the report viewer control. The report contains a subreport. The subreport renders images from external files. The problem is that i need to programmatically set the EnableExternalImages property of the subreport at run time. Without this, the subreport refuses to render ("Error: Subreport could not be shown" is the error message i get). I've set this property on the main/outer report programatically without issue using this statement:
Me.ReportViewer1.LocalReport.EnableExternalImages = True
However i need to do the same on the sub-report...so optimally, i would like to code something like this:
Me.ReportViewer1.LocalReport.Subreport1.EnableExternalImages = True.
Problem is, i don't see a property available that provides me direct access to the subreport's properties in this fashion. I've looked into using the SubreportProcessingEvent, however this event only exposes a limited number of properties of the sub-report (Reportparamaters, Datasources, ReportPath, etc..), but does not provide me with access to all of it's properties (e.g. EnableExternalImages property).
Thanks for any information...

Create RDL(C) with WCF datasource for ASP.NET MVC2 using Visual Studio 2010?

We've got two C# apps, one providing several WCF web services and the other, an MVC 2 web app, consuming them. We plan for the web app to provide numerous reports based on existing or new operations on the web services, using the WebForms ReportViewer. We need to use a report designer tool - the one used for RDLC files would be just fine. We're using VS 2010 and deploying to Azure.
I've spent a couple of days looking for a way to do this, without much progress.
There seem to be two routes to accomplishing this:
Use the ReportViewer in local mode - create RDLCs as part of the web app and use a local data source, either XML feeds from the web services or objects that are part of the web app (perhaps the from the clients created when the web services are added to the project as web references).
Have the ReportViewer show reports from an SSRS report server. It seems like RDLs can have XML data sources, including WCF services.
The first would be simpler, especially as I'm not sure we're going to need the extra infrastructure of setting up a report server to meet other requirements. But I simply haven't been able to connect to either an XML or object data source.
The second way seems to have a number of problems in addition to the added infrastructure: I haven't gotten the XML connection to work yet here either, but it seems like a little more reading and trial and error should get me there. Also, there's no Visual Studio 2010 tool that I could find that supports this type of report - you need to create them in SQL Server Business Intelligence Development Studio. Which is a flavor of VS 2008. So there's some significant extra work to get this set up to work with TFS 2010 so we can include our reports in version control, builds and deployment.
(Then there's also the complications of integrating WebForms into an MVC app. But I think those are manageable).
Any suggestions for other approaches to these requirements would be most appreciated.
Or, if you've gotten this to work, hearing how you did would be great.
I was able to use ReportViewer in local mode and reasonably meet the requirements we had. I'll describe how to do this in case anyone looking at this question was having similar problems.
Outline:
Create a data access object for the report.
Create a report (RDLC file).
Create a WebForm to display the report using the ReportViewer
control.
One thing it took me a while to understand: There are two phases of creating a report that seem very similar but have different purposes. When creating the RDLC file, there is a "design-time" binding to a data object that allows you to associate placeholders in report controls (tables, lists, etc) with data elements. Then, later, when adding a ReportViewer to the WebForm, there is another data binding that will connect the report with an instance of a data object to pull the report data from.
I. Create a data access object.
In step II.5 below, you will need to choose the namespace of this object. Here it also took me a while to realize is that Visual Studio has a predetermined set of namespaces for this and you just have to work within this. Fortunately one of them is your MVC project's Models namespace, which seemed like a logical place to put this. Actually, I created a child namespace, MyProjectWebRole.Models.ReportModels, which was okay with Visual Studio.
Here's an outline of my access object:
namespace MyProjectWebRole.Models.ReportModels
{
public class DataThing
{
public DataThing()
{
}
public int ThingId{ get; set; }
public decimal ThingCost { get; set; }
public DateTime ThingAcquisitionDate { get; set; }
public string ThingType { get; set; }
public static IList<DataThing> GetEveryThing()
{
ServiceClient client = null;
ThingsRequest request = null;
ThingsResponse response = null;
string errorID = "";
IList<DataThing> things = new List<DataThing>();
client = new ServiceClient();
request = new ThingsRequest();
response = client.ThingsReport(request);
}
foreach (ResponseThing rt in response.Things)
{
DataThing theThing = new DataThing();
theThing.ThingId = rt.Id;
theThing.ThingCost = rt.Cost;
theThing.ThingAcquisitionDate = rt.Date;
theThing.ThingType = rt.Type;
things.Add(theThing);
}
if (client != null) client.Close();
return things
}
}
}
ServiceClient, ThingsRequest, ThingsResponse and ResponseThing are defined when you add a ServiceReference to the web service where the data originates.
II. Create the report.
From a project folder's context menu:
Click on "Add" -> "New Item ..."
Select the "Reporting" template set in the left pane.
Select the "Report" template. A design surface for the new report appears.
Drag controls from the Toolbox to design the report. The first time
you drag a control that requires a dataset (table, matrix, guage,
graph, list) the Dataset Properties dialog will open:
Choose the data source.The "Data source" dropdown shows the
namespaces in which report data sources can be named.Choose the one
in which you defined your data access object.
Choose the dataset:The "Available datasets" dropdown includes all
the appropriate methods in the selected Data source namespace. The
method(s) of the data access object intended for this should be
among the choices. Select the one needed for this report. The data
it makes available will be displayed in the "Fields" list.
Configure the report control that triggered the Dataset setup.The
fields from the selected dataset can now be used as placeholders for
elements of controls added to the report.
Complete the report definition by including and configuring any
other report controls needed.
III. Create a WebForm to display the report.
Once the WebForm is created, add a ScriptManager control (from the
AJAX Extensions section of the Toolbox).
Add a ReportViewer control to the WebForm (from the Reporting
section of the Toolbox)
In the Design view of the WebForm, click on the ReportViewer control
to make it active.
Click the Smart Tag to open a "ReportViewer Tasks" dialog.
Open the "Choose Report" dropdown and select the RDLC file of the
report designed above.
Click "Choose Data Sources" to open a "Choose Data Sources" dialog.
The dataset you created and named in part II should be listed as a
"Report Data Source" and there should be a dropdown for it under
"Data Source Instance".
Open the dropdown for your data source and click the choice that
says ".
That brings up a "Data Source Configuration Wizard. Click on the
"Object" data source icon and, if you want, give it a more
meaningful ID than the default provided.
That brings up a "Configure Data Source" dialog for the new Object
data source you just created. In the "Choose your business object"
dropdown, you will again select
MyProjectWebRole.Models.ReportModels.DataThing
Click Next and then choose the "Select" tab.
Again, choose the method from you business object that will provide
the data to be bound to the report.
That's all there is to it. When you browse to your WebForm, it should query the web service and populate the report with the data provided.
Any additions and corrections to this are most appreciated!

Binding a database view to a c# .net gridview

I have been using excel to view the database tables by binding the sql database views in excel and making a spreadsheet. This works just fine but I want a solution in code.
Is there a way in C# ASP.NET to bind a database view directly to a gridview when given the view name as a string?
***SOLVED*****
I did some more research and found a solution. The main issue was that I didn't want to have to make any business objects or have a stored procedure on my database.
The solution I found was to use an SqlDataSource. I simply set the SqlDataSource.ConnectionString and set the SqlDataSource.SelectCommand to be "Select * From" +MyViewName and then bind the datasource to the gridview.
Using this method I essentially just have to pass in the table/view name and the gridview will be populated from the database directly. This allows me to use the same code and the only thing that needs changing is the database view name string.

Add Data to DataRepeater Control in winform

Visual Studio 2008 service pack 1 comes with Visual Basic Powerpack and has DataRepeatr control.
i want to know that how I can add data in this control. i have in memory data. the examples i found on net are about binding DataSet to DataRepeater by fetching data from database. i want to bind in memory data. how to do this.
by adding a new DataSet from Add New Item.
Create new DataTable in DataSet.
Add items from DataTable to DataRepeater using DataSource Explorer.
fill the data table from code.. thats the whole process i did.