Showing posts with label reportviewer. Show all posts
Showing posts with label reportviewer. Show all posts

Monday, March 19, 2012

LocalReport.Render problem

At the moment my Intranet contains a few reports which are all shown using one reportviewer. I use this bit of code to switch one RDLC for another

===

ReportViewer1.LocalReport.DataSources.Clear();

ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsstrafstudie_DataTable1","ObjectDataSource2"));

ReportViewer1.LocalReport.ReportPath = "rptstrafstudie.rdlc";

ObjectDataSource2.FilterExpression = "datum = '" + Request.QueryString["datum"]+ "'";

===

It works just fine ! Now I Want to skip the reportviewer VIEW and just let the people download EXCEL or PDF export. So I add this bit of code

===

Warning[] warnings;

string[] streamids;

string mimeType;

string encoding;

string extension;

byte[] bytes = ReportViewer1.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamids, out warnings);

FileStream fs = new FileStream(@."c:\output.xls", FileMode.Create);

fs.Write(bytes, 0, bytes.Length);

fs.Close();

===

But I keep getting the error "A data source instance has not been supplied for the data source "dsstrafstudie_DataTable1". Alltough I DO supply a DS instance only a few rules above ? What on earth am I doing wrong?

Thx in advance,

Puitje

Hi Puitje,

Did you find a solution for this error? I am experiencing the exact problem.

Thanks

|||Instead of using "ReportViewer1.LocalReport" create a new instance of a LocalReport and use that one.|||

I use a new variable LocalReport rp1, but error doesn't change ...

If i didin't use a datasource for the report the code works correctly.

Someone have any idea ?

Thanks

|||Did you add the datasource when you used Render?|||

Yes cause i copy the same code that visualize the Report correctly and i put it in a new function.

The function who render at video works correctly, the function who render manually give me the exception.

|||Are you sure that the objectdatasource you provided is correctly populated? Maybe you lost some event that populates it?|||I

I post the code :


these two function are called on Page_Load event ( the same on Page_PreRender).

The first function works correctly and display on my page the report with correct data.

The second function generate an exception on Render call.

He didn't find "DataforReport" istance.

The rdlc is a converted rdl.

FIRST

virtual public Boolean VisualizzaReport(ref Hashtable par)
{
ReportViewer rp1;
ReportDataSource ds1;
SqlDataSource sql1;
Database dbRep;
ControlParameter cp1;
Label l1;

// Definisce l'SqlDataSource per poi definire il ReportDataSource in funzione di questo
sql1 = new SqlDataSource();
sql1.ID = ReportPage.PageContent.SqlReportSource.ToString();
dbRep = new Database(this.NomeDatabase, this.NomeSP, ref sql1, 0);
sql1.SelectParameters.Clear();

foreach (DictionaryEntry de in par)
{
l1 = new Label();
l1.ID = "Label_"+de.Key.ToString();
l1.Text=de.Value.ToString();
l1.Visible = false;
this.content.Controls.Add(l1);

cp1 = new ControlParameter();
cp1.ControlID = l1.ID = "Label_" + de.Key.ToString();
cp1.Name = de.Key.ToString();
cp1.PropertyName = "Text";
cp1.Type = Type.GetTypeCode(de.Value.GetType());
// TypeCode.Int32;
sql1.SelectParameters.Add(cp1);
}
this.content.Controls.Add(sql1);
// Definisce il reportDataSource
ds1 = new ReportDataSource();
ds1.Name = "DataforReport";
ds1.DataSourceId = ReportPage.PageContent.SqlReportSource.ToString();

// Definisce il Report
rp1 = new ReportViewer();
rp1.ID = ReportPage.PageContent.ReportLocale.ToString();
rp1.ShowToolBar = false;
rp1.Width = new Unit(100, UnitType.Percentage); ;
rp1.Height = new Unit(100, UnitType.Percentage); ;
//rp1.ID = ReportPage.PageContent.ReportLocale.ToString();
rp1.LocalReport.DisplayName = this.NomeReport;
rp1.LocalReport.ReportPath = this.NomefileReport;
rp1.LocalReport.DataSources.Clear();
rp1.LocalReport.DataSources.Add(ds1);
rp1.LocalReport.Refresh();
this.content.Controls.Add(rp1);

return true;
}

SECOND

virtual public Boolean RenderReport(ref Hashtable par)
{
ReportViewer rp1;
ReportDataSource ds1;
SqlDataSource sql1;
Database dbRep;
ControlParameter cp1;
Label l1;

sql1 = new SqlDataSource();
sql1.ID = ReportPage.PageContent.SqlReportSource.ToString();
dbRep = new Database(this.NomeDatabase, this.NomeSP, ref sql1, 0);
sql1.SelectParameters.Clear();

foreach (DictionaryEntry de in par)
{
l1 = new Label();
l1.ID = "Label_" + de.Key.ToString();
l1.Text = de.Value.ToString();
l1.Visible = false;
this.content.Controls.Add(l1);

cp1 = new ControlParameter();
cp1.ControlID = l1.ID = "Label_" + de.Key.ToString();
cp1.Name = de.Key.ToString();
cp1.PropertyName = "Text";
cp1.Type = Type.GetTypeCode(de.Value.GetType());
// TypeCode.Int32;
sql1.SelectParameters.Add(cp1);
}
this.content.Controls.Add(sql1);
// Definisce il reportDataSource
ds1 = new ReportDataSource();
ds1.Name = "DataforReport" ;
ds1.DataSourceId = ReportPage.PageContent.SqlReportSource.ToString();

ReportViewer rp2;
rp2 = new ReportViewer();
rp2.LocalReport.ReportPath = "Fattura.rdlc";
rp2.LocalReport.DataSources.Clear();
rp2.LocalReport.DataSources.Add(ds1);
string deviceInfo =

"<DeviceInfo>" +

" <OutputFormat>PDF</OutputFormat>" +

" <PageWidth>8.5in</PageWidth>" +

" <PageHeight>11in</PageHeight>" +

" <MarginTop>0.5in</MarginTop>" +

" <MarginLeft>1in</MarginLeft>" +

" <MarginRight>1in</MarginRight>" +

" <MarginBottom>0.5in</MarginBottom>" +

"</DeviceInfo>";
byte[] data =rp2.LocalReport.Render("PDF", deviceInfo, out mimeType,out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(@."c:\prova.pdf", FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
//determine if format is rendered to the web or a file.

return true;
}

|||Why do you define 2 datasources? When do you add data to ds1?|||I think the refresh method in the first code triggers the datasource updating...

Wednesday, March 7, 2012

Local ReportViewer - Printing margins off by ~1/8 inch

I am printing my reports from my local report viewr, and the margins are
off by 1/8 inch if I include a header. It looks like printing shifts the
contents of the report 1/8 inch to the right, borking everything.
1. Report has a "header" area. Without this header, the printing is fine.
2. Report body is 7" wide
3. Margins are .75" (6/8) inch on all sides
4. Print Preview mode displays the report properly, centered
5. Output is similarly skewed on all printers (tried 4)
6. This is using the VS SP1 version of the RS dll's.
Setting the margins to Left: 0.625, Right: 0.875 (5/8&7/8) actually causes
it to print centered, so I know it is paying attention. When I do this, the
print layout mode shows the contents shifted to the left 1/8", as expected.
I assume that people print using this control, or at least it was tested,
so has anyone else seen this or is it a confirmed bug?
Thanks,
// Andrew Backer
P.S. In a related bug, if I include the header then the local viewer __insists__
on rendering the page at 8.5 inches wide, regardless of the fact that the
body is still 7". This doesn't seem to affect printing, but without the
header it only renders at the body width, 7", rather than giving me 1.5"
of blank spaceCheck the "Spacing" property under the Layout Tab of the Report Properties
window.
Set it to "0in".

Local Report Confusion

Okay, so I'm working with a local report via the Web ReportViewer
control, and there is something going on that I don't quite get. I
created my object datasource and it was available to me via the "data
source" window when i created my RDLC report. All good here. Well along
the way, I have made changes to the class that represents my data
source object, and here is what I'm seeing being auto-inserted into my
ASPX file:
<rsweb:ReportViewer ID="ReportViewer1" runat="server" >
<LocalReport ReportPath="MyReport.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="MyObject" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="MyObject1" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="MyObject2" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="MyObject3" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="MyObject4" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetMyObjects" TypeName="Merchant"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetMyObjects" TypeName="Merchant"></asp:ObjectDataSource>
By the time the "MyObject3" I started wondering if there is some hidden
(or at least not obvious) versioning going on with my object data
class, in that each time I change it and rebuild it, it is given a new
name in the data source pane. What's really odd though, is that only
the most recent appears to be available (assuming that is what is going
on). So why do all these new <rsweb:ReportDataSource /> rows keep
appearing in my ASPX? Am I somehow creating multiple connections to my
datasource? Is this a result from each time I change the class that
represents my underlying data source object? Do I need to keep all
these entries, or can I dump all the old ones and just keep the newest
one? Finally, how did I end up with multiple "OjectDataSource" objects?
I started deleting them, and then having to repoint the reportviewer
control to an existing ObjectDataSource control.
If anyone can clarify what is going on, I would be very grateful.
Thanks!
ChrisQuick update: I see that changing my class isn't what causes the
insertion of new <rsweb:ReportDataSource /> items in my ASPX. Just now
I added a new table, and now when I run it I get the error "A data
source instance has not been supplied for the data source 'MyObject5'."
If you look at my previous post, there was no "MyObject5". Now when I
click on the smart tag for the reportviewer object in design view and
select "Choose Data Sources" I get the pop up grid that now asks me to
associate an ObjectDataSource with this new MyObject5. So again, in
this dialog, I have a column called "Report Data Source" and a column
called "Data Source Instance". Right now my grid (after associating
this latest one) looks something like this:
Report Data Source Data Source Instance
MyObject ObjectDataSource1
MyObject1 ObjectDataSource1
MyObject2 ObjectDataSource1
MyObject3 ObjectDataSource1
MyObject4 ObjectDataSource1
MyObject5 ObjectDataSource1
Thanks!

Local processing, ReportViewer and PDF

I hope this is the right Newsgroup, if not I'd be glad for directions to the
right one.
Regarding the ReportViewer control shipped with VS.NET 2005 Beta 2, I've
seen that in local processing mode the only renderer is Excel. Does anybody
know if this will be like that also in the final version of VS.NET 2005 ?
Does anybody know any commercial PDF rendering extension for the
ReportViewer?
Thanks,
Ethem AzunAfter writing this, I just run into these;
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=b5f3f1cf-4614-474e-b423-0fa9c35f09e1
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=7acce9a3-35f5-4f6b-8789-236db4b45a03
Ethem Azun
"Ethem Azun" wrote:
> I hope this is the right Newsgroup, if not I'd be glad for directions to the
> right one.
> Regarding the ReportViewer control shipped with VS.NET 2005 Beta 2, I've
> seen that in local processing mode the only renderer is Excel. Does anybody
> know if this will be like that also in the final version of VS.NET 2005 ?
> Does anybody know any commercial PDF rendering extension for the
> ReportViewer?
> Thanks,
> Ethem Azun