Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

How To Save New Report To Database Without Key Violation

edited September 2004 in General
My application saves the report objects to database. The fields in the
table are CategoryName, ReportName, and ReportObject. The problem that I
have occurs when I allow the user to create a new report by executing File |
New. When it comes time to save the new report I have different problems
depending on what I try to do.

When I enter the report designer I already have a category and report name
that the user has already picked. Any new report should have that name, and
a record has already been created for it in the reports database before the
report designer is invoked. When I try to assign the report name and
category in a before post method of the reports database, I get a key
violation when the Template.SaveToDatabase command is executed. This
happens because the reports database is in an insert mode rather than an
edit mode.

After File | New, the Category and and ReportName Fields are blank. If I do
not assign them, then I get an error saying that the fields cannot be null.
If I do assign them then I get a key violation, because the record already
exists, because the reports table is in "insert" mode..

I've noticed that after a File| New, if I execute a save from the designer,
I get a dialog prompting me for a report name. The report name that was
assigned on the designer entry is listed as a selection in the list box. If
I then select that report name, I get a message saying that the reports
exists and I am prompted if I want to overwrite it. If I say yes, then the
report is successfully saved. The problem is that I do not want the user to
have to go through that. I should be able to tell the report designer to
save the NEW report to the originally assigned name within code.

How can I do this?

Thanks,

Al Willis

Comments

  • edited September 2004
    Al,

    First, have you taken a look at the Report Explorer. This was designed to
    prevent exactly what you are encountering, and gives your users an easy to
    use interface for creating, deleting, and editing reports with the
    ReportBuilder end user designer. Before going any further with this I would
    suggest taking a look at some of the ReportBuilder end user examples and see
    if that can work for you.

    I am having a bit of trouble following the order of operations in your
    application. When you initially enter the designer, do you want an empty
    report to display with a given name? When you try to save a template to the
    database, ReportBuilder will automatically search the Name field and if
    there is a match, it will enter edit mode and overwrite the existing report.
    If there is no match, the database will be set into insert mode and the new
    report is written to a new record in your database. By assigning the report
    name before trying to save the report, you are working against the way
    ReportBuilder was designed. This is why you are receiving a message asking
    if it is ok to overwrite an existing report, even though nothing actually
    exists yet.

    I would suggest using the TppDesigner.Menu property to gain control of the
    Save and New options in the File menu, then adding your own code to handle
    the saving and creating of new reports to your individual database.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    Nick,

    Thanks for the reply.

    I solved the problem. All I had to do was to assign the
    ppReport1.Template.DatabaseSettings.Name the desired report name in the
    designer's ReportSelected(Sender: TObject) event.

    Al

This discussion has been closed.