C# Telerik reporting no datasource at designtime dataschema - c#

I use vs 2010 and telerik reporting 2013 Q1
use the next code to bind a datatable to report.
Reports.Report1 report = new Reports.Report1();
Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = CreateData().Tables[0];
report.DataSource = objectDataSource;
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
TelRptViewer.ReportSource = reportSource;
My report contains a simple table dataitem with 3 columns.
I have already read this topic in help.
Working With Data at Design Time-Data source available only at runtime
"This approach is useful when you cannot get the report's data source at design time or want to avoid loading real data into Visual Studio at design time. In this case you would have to mock your data just to enable the Report Designer to show any data schema. This will enable you to adjust the layout of the report and bind report items to the available data fields, while the real data will be loaded only at runtime either in NeedDataSource event or in the actual application. "
In simple reportviewer there was an xsd which prove the data schema for report.
In this viewer how its is possible to make this data schema or similar? Or there is another way to do this?
Thx.

You never said whether you have added report items (e.g. TextBoxes) in your Report1 class. Those textboxes need to have binding expressions as Value i.e. = Fields.MyDataColumn1.
Only then, would the report actually show data. You could also add a call to TelRptViewer.RefreshReport(); which is required for some viewers (e.g. Windows Forms)
Good luck!

You can bind Telerik Reports to objectdatasource at design time and drag your fields directly to the REport using Visual Designer
To create and run the reports using Visual Studio or the new Desginer while binding it to a objectdatasource : All you have to do is hardcode the connection string into the class of your data method . and inside that method use the connection string. Check my blog: http://flying2mind.blogspot.com/2013/10/creatingrunning-telerik-reports-in.html
http://flying2mind.blogspot.com/2013/07/telerik-report-doesnt-see-fields-of.html

Basically, you can add your datasource code in NeedDataSource event of your report and set the datasource. NeedDataSource event is used when there is no data source for the report.

private void Report1_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Report rpt = (Telerik.Reporting.Processing.Report)sender;
this.Report1DS.Parameters[0].Value = your value to be passed to data source..;
// Similarly you can add more values of parameters.
rpt.DataSource = Report1DS;
}

Related

Dynamically binding Report to ReportViewer component

I want to show different reports in ReportViewer component, based on selected text in comboBox, but it seems I'm having difficulties binding data sources to reports.
This is the code in comboBox.TextChanged(object sender, EventArgs e) handler
reportViewer.Reset();
this.reportViewer.LocalReport.ReportEmbeddedResource = "ReportViewer." + MapComboBoxItem2ReportName(cbReports.Text) + ".rdlc";
this.reportViewer.RefreshReport();
I'm getting an error: "A data source instance has not been supplied for the datasource DataSet1".
What else do I need to do so I could load report dynamically?
When you change the reportViewer's source report, you have also have to to set the datasources for it. Normally, the designer handles that for you (take a look at the designer generated code to see how it handles it), but changing the source report resets the LocalReport object of the control.
Therefore you need to supply all datasources to your report so that it can display correctly :
this.reportViewer.LocalReport.ReportEmbeddedResource = "ReportViewer." + MapComboBoxItem2ReportName(cbReports.Text) + ".rdlc";
this.reportViewer.LocalReport.Datasource.Add("Datasource1", whateverIsYourDatasourceObject)
this.reportViewer.RefreshReport();
You have to add the same line for every datasource defined in your report. If you're not sure about the datasources names you need to use, look at the designer generated code to see what they are. You can also use the following code to find out all the report's datasources names :
this.reportViewer.LocalReport.GetDataSourceNames()
If your report has variables, you need to define them too, otherwise you'll get the same error.
Hope that helps
you left out the ReportPath.
this.reportViewer.LocalReport.ReportPath = "Reports\\" + MapComboBoxItem2ReportName(cbReports.Text) + ".rdlc";
this.reportViewer.LocalReport.ReportEmbeddedResource = "ReportViewer." + MapComboBoxItem2ReportName(cbReports.Text) + ".rdlc";
this.reportViewer.LocalReport.Datasource.Add("Datasource1", whateverIsYourDatasourceObject)
this.reportViewer.RefreshReport();
A data source instance has not been supplied for the datasource
DataSet1
Please make sure first parameter name is "DataSet1". Which would be the one you created a new DataSource in .rdlc Design Form and named as "DataSet1".
this.reportViewr.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",
yourDataSet.Tables[0]));

How to filter data in RDLC report?

I am new to RDLC reports in Visual Studio 2010.
I am working on a Website, in this I have used report feature of VS2010. I use ReportViewer to show Report1.rdlc. It is showing it perfectly. Now my requirement is to filter data in report at runtime. I go through this question but not able to understand it's answer.
Because Report1.rdlc is not available in code behind.
Now, how can I filter report's data at runtime?
Surely you assign the dataset to the rdlc report, and in the page of your reportviewer, you would be using an object datasource (and therefor an XSD dataset with datatables), which encapsulates the query.
The query naturally has a where clause, in which you insert your parameters to filter the data by, like:
WHERE (Table.Field = #Param OR #Param = A_Default_Value)
Now add the controls you like to the page before calling the report (drop-down lists, textboxes, etc..), those controls filter the Object datasource, which is mapped to a dataset in the rdlc report, and thus, the report would be filterd upon clicking on a certain button, e.g. Show Report, to refresh the object datasources (databinding them) and re-showing the report in the reportviewer.
You may consider assiging the values of the filtering controls to parameters in the rdlc, so that you may show the parameters of the report in its header upon generating it:
Parameters!ParameterName.Value
Hope that helps you.
How are you getting the data from Server, etc. Are you binding to a datatable result? If so, you can just have your query apply the filter when extracting data to begin with so you don't have to do anything special in the actual report.
Per your feedback, if you are getting a DataTable, then applying a filter should be easy like
DataTable oDT = YourSQLCommandToGetData();
oDT.DefaultView.RowFilter = "SomeColumn = x and OtherColumn = y";
And then run your report. If you want to take it to another level and ENSURE you don't have any unwanted records, you could even do something like
DataTable oNewFilteredResult = oDT.DefaultView.ToTable();
Then, you can assign the NEW table to call the RDLC.

I have data in my dataset, but it's not showing up in my reportviewer?

I have a program that shows data in a datagridview. The data in the datagridview comes from a table in a dataset. The data looks good on the screen so I decided to add a way to print the data.
I created a new form, added a reportviewer control, and designed the report. I used my dataset as the datasource for the report.
I then added a button to my original form so that when it was pressed, it would show the form with the reportviewer control.
My problem is, when I hit the print button, it takes me to my reportviewer control form, but it shows my report with only the headings, no data. It's like my dataset has no data in it! But, when I step through with debug, it shows over 1000 rows in my dataset.
So, my question is, what have I forgotten to do? The data is there, it shows up on one form (with the datagridview) but it doesn't show up on the reportviewer control (only the headings).
There was really no coding involved. I just made a new form, added the reportviewer control, designed the report and told it to use my dataset as the datasource. Typically, this works for me. I can't imagine why it's not working.
Thanks for any help or advice!
Here's the code that I use to show the report:
private void btnPrint_Click(object sender, EventArgs e)
{
Form showReport = new frmPrintView();
showReport.Show();
}
Here are images of my two screen. The data is obviously in my dataset, otherwise there would be none on the first screen. The second screen, though, seems to show my dataset as being empty since nothing appears but the headings.
I think you are missing the dataBind method:
From the Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4:
ASP.NET controls require you to execute the DataBind method on the control to indicate
that the data is ready to be rendered. If you don’t execute the DataBind method, the control won’t render. When executing the DataBind method on a control, the control is obliged to call the DataBind method on its child controls. This means that you can execute the DataBind method on the Web form, and it will call the DataBind method on all its controls
add it to the form load event on your form report
video for support https://www.youtube.com/watch?v=hkDIDTNbA6M
u need to again add data into ur dataset from database
billDataSet b1 = new billDataSet();
SqlDataAdapter s = new SqlDataAdapter("select * from TblOrder",con);
s.Fill(b1,b1.Tables[0].TableName);
ReportDataSource rds = new ReportDataSource("orders",b1.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportView er1.LocalReport.Refresh();
this.TblOrderTableAdapter.Fill(this.billDataSet.TblOrder, d1.ToString(),d2.ToString(), companyid);
this.reportViewer1.RefreshReport();

Using subreport inside an SSRS table/tablix cell

In my application I have a report with one subreport contained inside a table cell. Within the SubreportProcessing event handler I supply a different set of data foreach instance of the subreport. In VS 2008 this worked okay. However, when I switched over to VS2010 and upgraded the report file format, the behavior changed. All subreport instances in the master table now contain the data that I supplied for the first table row. My code looks like this
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
// _index is a global variable that is reset to zero in the DataBind procedure.
Trip currentTrip = _trips[_index];
e.DataSources.Add(new ReportDataSource("DataSourceName", currentTrip.Items));
_index++;
}
Is this the intended behavior? How can I now supply different datasets for multiple instances of the same subreport inside a table?
Thanks in advance.
Vladislav
After some poking around and tinkering with my code, I found a workaround. The solution is to create a dummy parameter in the subreport, which you then need to bind to a field in the tablix dataset. Any field will do as long as both the subreport parameter and the tablix dataset field are type-compatible. You don't have to do anything with the parameter in the subreport, but now SSRS displays multiple instances of the same subreport, a separate one for each row in the tablix.
Hope this will be helpful for someone else, too.
Vladislav

How to set datasource for fields in XtraReports without having a dataset at design time?

I'm taking a look now to XtraReports reporting tool and there's something that I don't get it yet.
How do I set the data source for a certain field (showed in the report as a Label I guess), without having to build a connection, adapter and dataset at design time but doing it programatically.
For example, I can have a table called "User" with 3 fields: UserId, Username and Password.
In the report designer I place 3 labels (and here's my question) set the datasource for showing the 3 database fields.
Then, in the code behind, I create a connection, execute a command, fill a dataset, create a report instance, pass the datatable to it and show the report preview.
Is this possible? Let me know if it isn't clear enough.
Thanks!
You could set your Report's DataSourceSchema property to an XML schema that represents your DataSource. That will let you use the Report Designer to set your data bindings at design time without establishing a connection to the database each time.
Here's how I do it:
Once I have my report query mostly finalized, I run the code once with a call to
myDataSet.WriteXml("C:\myDataSourceSchema.xml", System.Data.XmlWriteMode.WriteSchema)
Then in the report designer I set the Report's DataSourceSchema property to the newly created file. This will populate the Report Designer's Field List tab so you can bind at design time. That way you only have to have a valid data source once (or any time you change your columns). You can definitely still do Przemaas's approach and do all of your data bindings in code, but I prefer to let the designer handle most of the work.
Building a report without a dataset, you would use an IList object ... so follow this nice tutorial
How to: Bind a Web Report to an Array List
https://documentation.devexpress.com/#XtraReports/CustomDocument3851
Yes, it is possible. You can define necessary databindings in the code:
this.xrLabel1.DataBindings.Add(new DevExpress.XtraReports.UI.XRBinding("Text", data, "Name", "aaa"));
Text here is property on the XrLabel
class. I assume that you want to
display bound field as text in label.
data is your object with data
"Name" is name of field that you want to display
"aaa" is display format, applicable in case you want to display values with custom formatting
Basically databindings in XtraReport act pretty much the same way as standard windows forms databindings.
Let me know is you need more guidelines
Here is an alternate..
rtpObject.DataSourceSchema = dataSet.GetXmlSchema();
before doing this set modifier property as public
InvoicePrinting_Rpt InvoicePrintingRpt = new InvoicePrinting_Rpt();//report object
InvoicePrintingRpt.BillDetails.Report.DataSource = ds_Invoice;
InvoicePrintingRpt.Report.DataMember = ds_Invoice.Tables[0].TableName;
//bellow third parameter as your column name.
InvoicePrintingRpt.lbl_BillHead.DataBindings.Add("Text", null, "BILL_DESCRIPTION");
InvoicePrintingRpt.lbl_Det_Date.DataBindings.Add("Text", null, "TRANSACTION_DATE");
InvoicePrintingRpt.lbl_ISINCode.DataBindings.Add("Text", null, "ISIN_CODE");
ReportViewer1.Report = InvoicePrintingRpt;//assign report obj
ReportViewer1.Report.Name = "DevExpress_Reports.InvoicePrinting_Rpt";
ReportViewer1.DataBind(); //binding
XRBinding binding = new XRBinding("Text", ageingBindingSource, "ageing_contactsLookup.name");
this.xrLabel19.DataBindings.Add(binding);
// or //
XRBinding binding = new XRBinding("Text", dbaDataSet, "transactions.fk_transitems_transactionid.name2");
this.xrTableCell1.DataBindings.Add(binding);

Categories