Save a report layout without its datasources definitions

Stimulsoft Reports.NET discussion
Post Reply
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Save a report layout without its datasources definitions

Post by Fabio Pagano »

I want to save a report layout without its datasources definitions. This is because i will programmatically manage the designer, calling the "regdata" anytime the designer is invoked.

Consider this scenario:

1. I have a dataset called "ds" with a datatable called "dt" containing only the column "A".
2. I create the report object, "regdata" the dataset, call the designer then i programmatically save the layout.
3. I have a dataset called "ds" with a datatable called "dt" containing only the column "B"
4. I load the report layout previously saved in step 2, "regdata" the (new) dataset, call the designer: i find two columns in the datasource, "A" (that doesn't exist anymore in my dataset) and "B". I only want to see "B".

This is the code:

Code: Select all

        
        'STEP 1

        Dim ds As DataSet
        ds = New DataSet
        ds.DataSetName = "ds"
        Dim dt As DataTable
        dt = New DataTable
        dt.TableName = "dt"
        dt.Columns.Add("A")
        ds.Tables.Add(dt)

        'STEP 2

        Dim rpt As Stimulsoft.Report.StiReport
        rpt = New Stimulsoft.Report.StiReport
        rpt.RegData(ds)
        'IN THE DESIGNER DATASOURCE I CORRECTLY SEE 
        'THE DATASOURCE WITH THE COLUMN "A" ONLY
        rpt.Design()
        rpt.Save("c:\\test.mrt")

        rpt = Nothing

        'STEP 3

        ds = New DataSet
        ds.DataSetName = "ds"
        dt = New DataTable
        dt.TableName = "dt"
        dt.Columns.Add("B")
        ds.Tables.Add(dt)

        'STEP 4

        rpt = New Stimulsoft.Report.StiReport
        rpt.RegData(ds)
        rpt.Load("c:\\test.mrt")

        'NOW IN THE DESIGNER DATASOURCE I WILL
        'SEE THE COLUMN "A" THAT IN MY DATASET
        'DOESN'T EXIST ANYMORE, I WANT TO SEE
        'ONLY THE COLUMN "B"

        rpt.Design()
This is the designer datasource the first time:

Image

This is the designer datasource the second time, i don't want the column "A" because it doesn't exist anymore in the datatable:

Image

Thanks.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Save a report layout without its datasources definitions

Post by Vital »

You can remove all data sources from dictionary with following code:

Code: Select all

report.Dictionary.Datasources.Clear();
For synchronize report dictionary with new data you can use method Synchronize:

Code: Select all

report.Dictionary.Synchronize();
Thank you.
Post Reply