• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this document? Why not share!

Reportviewer Untyped Dataset

on

  • 2,378 views

 

Statistics

Views

Total Views
2,378
Views on SlideShare
2,378
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Reportviewer Untyped Dataset Reportviewer Untyped Dataset Document Transcript

    • I was in search of binding a dataset form my application to the reportviewer control on winform/webpage. The I came across this article and it worked for me. Hope others get through from this too…. Sorce: http://www.topxml.com/rbnews/XML/re-76790_DYNAMIC-BINDING-OF-REPORTVIEWER-CONTROL- TO-UNTYPED-DATASET.aspx 1. Drop a ReportViewerControl to your favourite webform 2. Drop a new DataSet in the project (DataSet1) 3. Create a DataTable in DataSet's XSD (DataSet1.xsd) which should define the structure of <Books.xml> I created Table1 which defines 2 types. I guess 2 are enough!! - Book_ID (of type System.Int32) - Title (of type System.String) 4. Drop a new RDLC file to project. You will notice the DataSet1 and DataTable1 being shown in quot;WebSite Data Sourcesquot; + DataSet1 - DataTable1 - Book_Id - Title 5. Drop a table to it. Fields!Book_ID.Value and Fields!Title.Value) Drag and drop the Fields ( 6. use the CODE LISTING 2 in Page_Load. NOTE: Pay attention to this line: Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource(quot;DataSet1_DataTable1quot;, Dt)) DataSet1_DataTable1 is the link to this hack. We are telling ReportViewer to bind this table quot;Dtquot; of ours (which you might have got from somewhere) to a dataset which is understood by RDLC.
    • Note: You do not have to chose this RDLC in quot;ReportViewer Tasksquot;. Which means rsweb:ReportViewer component is free to chose it's local report in runtime. Check the neat rsweb:ReportViewer component in CODE LISTING 3. Here is how it looks when you bind it in design mode. But these all we are doing in RUN TIME. ID=quot;ReportViewer1quot; runat=quot;serverquot; Height=quot;499pxquot; <rsweb:ReportViewer Width=quot;861pxquot; > <LocalReport ReportPath=quot;Report1.rdlcquot;> <DataSources> <rsweb:ReportDataSource DataSourceId=quot;ObjectDataSource1quot; Name=quot;DataSet1_DataTable1quot; /> </DataSources> </LocalReport> </rsweb:ReportViewer> <asp:ObjectDataSource ID=quot;ObjectDataSource1quot; runat=quot;serverquot; SelectMethod=quot;GetDataquot;TypeName=quot;DataSet1TableAdapters.quot;></asp:ObjectDataSo urce> CODE LISTING 1: Books.Xml [XML] version=quot;1.0quot; encoding=quot;UTF-8quot;?> <?xml BookRoot SYSTEM quot;E:ProjectsXML TRAININGDay 1XML <!DOCTYPE Examplesbooks.dtdquot;> <BookRoot> ISBN=quot;Ind-123-4-5quot; Date=quot;3.14 mod 5quot;> <Book AuthID=quot;a1quot;> <Author WorkedWith=quot;a2quot;>William</Name> <Name
    • <Location>GB</Location> </Author> AuthID=quot;a2quot;> <Author WorkedWith=quot;a1quot;>Dennis</Name> <Name <Location>USA</Location> </Author> you like it</Title> <Title>As <Price>100$</Price> CountryId=quot;GBquot;>GB</SoldAt> <SoldAt CountryId=quot;USquot;>US</SoldAt> <SoldAt CountryId=quot;INDIAquot;>India</SoldAt> <SoldAt Media</Publisher> <Publisher>Tech </Book> </BookRoot> [XML] CODE LISTING 2: Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Protected Handles Me.Load ReportViewer1.ProcessingMode = ProcessingMode.Local Dim rep As LocalReport = ReportViewer1.LocalReport quot;Report1.rdlcquot; rep.ReportPath = ' Lets get a dataset Dim ds As DataSet = New DataSet(quot;DynDSquot;)
    • ds.ReadXml(HttpContext.Current.Request.MapPath(quot;.Books.xmlquot;)) Dim Dt As New DataTable() Dt = ds.Tables(0) 'Table name = Book Me.ReportViewer1.LocalReport.DataSources.Clear() Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource(quot;DataSet1_DataTable1quot;, Dt)) End Sub CODE LISTING 3: Just for reference, how your aspx page's HTML should look like.(completly unneccesary) <body> <form id=quot;form1quot; runat=quot;serverquot;> <rsweb:ReportViewer ID=quot;ReportViewer1quot; runat=quot;serverquot; Height=quot;499pxquot; Width=quot;861pxquot;> </rsweb:ReportViewer> </form> </body>