none
Setting Report Fields Dynamically RRS feed

  • Question

  • Is it possible to execute code before rendering a report (i.e. replace field values programatically)? Or would I need to perform these operations before filling the dataset being reported on or in a stored procedure? Im using the report viewer and report object in visual studio 2005, not the sql server 2005 reporting services.
    Wednesday, July 18, 2007 3:03 PM

All replies

  • I just got this going myself. Add enough data sources to do everything you need to do. Lisa, in this forum, told me to use a literal in the SQL select statement on those data sources which will provide dynamic info, such as "SELECT 'happy' AS StateOfMind" . Notice there is no FROM and no table name. You must still provide the connect string to the data source, though. On the page prerender event, write whatever value into DataSourceXX.SelectCommand. You can stuff another literal statement, or you can use a statement that reads a table. In the literal example I gave, "StateOfMind" would be the data item name the report would use. After setting all your data sources call the refresh method on the report viewer as in: ReportViewerXX.LocalReport.Refresh() . That's it!
    Wednesday, July 18, 2007 8:39 PM
  •  Faticus wrote:
    Is it possible to execute code before rendering a report (i.e. replace field values programatically)? Or would I need to perform these operations before filling the dataset being reported on or in a stored procedure? Im using the report viewer and report object in visual studio 2005, not the sql server 2005 reporting services.

     

    Yes,

    use the code section in the report properties. now instead of setting the value of your textbox to what the fields from the dataset use the code.fuinction(parameters) instead.

     

    Paul.G.

    Friday, July 20, 2007 8:04 PM
  • Wednesday, July 25, 2007 8:48 PM