One .mrt file for different reports

Stimulsoft Reports.WEB discussion
bghalayini
Posts: 7
Joined: Tue Nov 01, 2011 3:20 am

One .mrt file for different reports

Post by bghalayini »

Hi,

I'm evaluating your product and I think we are going to buy them.
However I have an important question, which is: Can I load one generic .mrt file and change the SQL Queries on runtime? So I can feed it different queries on code behind?
If such scenario is doable, please do let me know how.

P.S: I'm using Stimulsoft Web Viewer and Designer.

Your help would be appreciated.

Thanks.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

One .mrt file for different reports

Post by Alex K. »

Hello,

As a way, you can use the following code:

Code: Select all

((StiSqlSource)report.Dictionary.DataSources["DataSourceName"]).SqlCommand = newSqlCommand;
Thank you.
bghalayini
Posts: 7
Joined: Tue Nov 01, 2011 3:20 am

One .mrt file for different reports

Post by bghalayini »

Thank you,
What about the Fields? how can I add Fields "on the fly" on runtime?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

One .mrt file for different reports

Post by Alex K. »

Hello,


You can use the following code.
New connection string:

Code: Select all

report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Add DataSources:

Code: Select all

StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Add Columns:

Code: Select all

foreach (DataColumn col in dataTableDS1.Columns)
{
     DS1.Columns.Add(col.ColumnName, col.DataType);
}
Add Relations:

Code: Select all

StiDataRelation dataRelation = new StiDataRelation("MyRelation", parentDS, childDS, new string[] { "Field" }, new string[] { "Field" });
report.Dictionary.RegRelations();
report.Dictionary.Relations.Add(dataRelation);
Thank you.
bghalayini
Posts: 7
Joined: Tue Nov 01, 2011 3:20 am

One .mrt file for different reports

Post by bghalayini »

Dear Aleksey,

I tried your code and changed

Code: Select all

foreach (DataColumn col in dataTableDS1.Columns)
{
     DS1.Columns.Add(col.ColumnName, col.DataType);
}
to

Code: Select all

foreach (DataColumn col in DS1.Columns)
{
     DS1.Columns.Add(col.ColumnName, col.DataType);
}
However it did not return any data.

Code: Select all

StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
: is "DS1" should be a name in the .mrt file?

Please advice what I am missing.

Thanks,
Bilal

Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

One .mrt file for different reports

Post by Alex K. »

Hello,

Please check the following code:

Code: Select all

SqlConnection conn = new SqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select * from DS1", conn);
DataTable dataTableDS1 = new DataTable();
conn.Open();
da.Fill(dataTableDS1);

StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
foreach (DataColumn col in dataTableDS1.Columns)
{
    DS1.Columns.Add(col.ColumnName, col.DataType);
}
Thank you.
bghalayini
Posts: 7
Joined: Tue Nov 01, 2011 3:20 am

One .mrt file for different reports

Post by bghalayini »

Hi Aleksey,

I tried you code. However it still returning empty data and even no columns names are displayed in the report.

Below is my code:

Code: Select all

            strConn = Session["strCustomerConn"].ToString();
            StiReport report = new StiReport();

            SqlDataAdapter da = new SqlDataAdapter("select * from students", strConn);
            DataTable dataTableDS1 = new DataTable();
            da.Fill(dataTableDS1);

            string appDirectory = HttpContext.Current.Server.MapPath(string.Empty);
            report.Load(appDirectory + "./App_Data/Report.mrt");

            StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM students", true, false);

            foreach (DataColumn col in dataTableDS1.Columns)
            {
                DS1.Columns.Add(col.ColumnName, col.DataType);
            }

            StiWebViewer1.Report = report;
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

One .mrt file for different reports

Post by Alex K. »

Hello,

You need add the following code:

Code: Select all

...
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", connectionString));
report.Dictionary.DataSources.Add(DS1);

StiWebViewer1.Report = report;
Thank you.
bghalayini
Posts: 7
Joined: Tue Nov 01, 2011 3:20 am

One .mrt file for different reports

Post by bghalayini »

Hi Aleksey,

I dont know what I am missing...it still returns no data!

If you can attach me a sample of my scenario described above (including the .mrt file) it would me more than appreciated.

Thanks,
Bilal
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

One .mrt file for different reports

Post by Alex K. »

Hello,

Please send your sample which reproduces the issue for analysis.

Thank you.
Post Reply