Runtime editing of SelectCommand property

edited 11:26AM in FastReport .NET
Hello,

I have added a datasource to my report and defined a query for it. I want to perform such a complex variations of the query that I need to be able to change the whole where clause of the query (parameters are not enough). I do not want to transfer all the rows the table contains via network and that is why I don't want to use Filter property of the databand.

So how can I assign the SelectCommand property of a table in startreport eventhandler (or elsewhere) to value of a report parameter?



Comments

  • edited October 2008
    Hello,

    Try this way:
    TableDataSource ds = Report.GetDataSource("MyTable") as TableDataSource;
    if (ds != null)
      ds.SelectCommand = (string)Report.GetParameterValue("MyParam");
    

    You can do it inside the Report.StartReport event handler (either in the script or your C# code).
  • edited 11:26AM
    Thank you.





    AlexTZ wrote: »
    Hello,

    Try this way:
    TableDataSource ds = Report.GetDataSource("MyTable") as TableDataSource;
    if (ds != null)
      ds.SelectCommand = (string)Report.GetParameterValue("MyParam");
    

    You can do it inside the Report.StartReport event handler (either in the script or your C# code).
  • edited 11:26AM
    Another question:

    I get error "System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. at System.Data.DataSet.FailedEnableConstraints()"

    In my query I join "units" to "events" so if one unit has multiple events then the result has multiple rows with same unit id what makes the error.

    So how can I disable that primary key (and other) constraints from dataset? I have used the report designer to define these queries and I do not want that resulting datasets have any constraints.
  • edited 11:26AM
    FastReport just executes the SQL that you wrote and fills the table with result data; it does not use any constraints. Do you able to write that query in the Visual Studio? If so, how can I reproduce it?
  • edited 11:26AM
    The report works fine whenever the result does not contain these "duplicate rows".

    If I right click my datatable object in the designer and choose "View Data..." on the first time I get error message:
    "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

    if I try the same again then I can view the data but there are these red marks in the cells where are same values. Tooltip of the marks says "Column unitID is constrained to be unique. Value '1234' is allready present."

    Im not expert on datasets or visual studio, but for me it seems that you can reproduce it just by making query and making join so that it will result multiple rows of first tables primary key.

    like:
    SELECT unitID
    FROM units JOIN events ON units.unitID = events.unit

    AlexTZ wrote: »
    FastReport just executes the SQL that you wrote and fills the table with result data; it does not use any constraints. Do you able to write that query in the Visual Studio? If so, how can I reproduce it?
  • edited 11:26AM
    Does your "units" table contains autoincrement fields?
  • edited 11:26AM
    No it does not contain autoincrement fields.

    Anyway now I got it working by just taking the "eventID" field to the query as the first field so that the first field is always unique. (Little bit strange "feature" but I just need my report working [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> ) One more question (again): I have put a one row table to a databand and I want that the cells of the table grow whenever one cell has so much data that it does not fit to it. I have set the "CanGrow" property of the table and databand to true but it does not work. Do I have to set some other properties also?[/img]
  • edited October 2008
    If you have a test case for me, it would be helpful. I could take a look at it and try to solve the problem.
    wrote:
    I have put a one row table to a databand and I want that the cells of the table grow whenever one cell has so much data that it does not fit to it. I have set the "CanGrow" property of the table and databand to true but it does not work. Do I have to set some other properties also?

    Select the table row and set its AutoSize property to true. You can do this in the row's context menu as well. The table itself does not use the CanGrow/CanShrink properties, so I'll hide them.
  • edited 11:26AM
    I'll try to make a test case for you in the near future.

    Now I get the following error everytime when I switch to page 2 in the report preview and when the table rows AutoSize property is true. When the AutoSize property is false then the error does not occur.

    (In my report I have PageHeader, ColumnHeader, Data, Column Footer and Page Footer. Data contains the table that expands to two pages)


    ************** Exception Text **************
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)
    at FastReport.Table.TableRowCollection.get_Item(Int32 index)
    at FastReport.Table.TableBase.IsVisible(FRPaintEventArgs e)
    at FastReport.ReportPage.Draw(FRPaintEventArgs e)
    at OEgLHQCnJP0SE8c59lA.OtwZyPC6aOjJDZUfvic.C5OA6W38d(Graphics , Boolean )
    at OEgLHQCnJP0SE8c59lA.OtwZyPC6aOjJDZUfvic.OnPaint(PaintEventArgs )
    at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
    at System.Windows.Forms.Control.WmPaint(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    *********************************************************************************


  • edited 11:26AM
    Sorry, I can't reproduce it. Do you able to do this in the Demo.exe? If so, you may prepare a report file and send it to me (tz@fast-report.com).

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.