Page 1 of 2

One .mrt file for different reports

Posted: Tue Nov 01, 2011 3:33 am
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.

One .mrt file for different reports

Posted: Tue Nov 01, 2011 8:53 am
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.

One .mrt file for different reports

Posted: Tue Nov 01, 2011 10:17 am
by bghalayini
Thank you,
What about the Fields? how can I add Fields "on the fly" on runtime?

One .mrt file for different reports

Posted: Wed Nov 02, 2011 5:27 am
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.

One .mrt file for different reports

Posted: Fri Feb 17, 2012 8:42 am
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


One .mrt file for different reports

Posted: Mon Feb 20, 2012 3:08 am
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.

One .mrt file for different reports

Posted: Mon Feb 20, 2012 10:06 am
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;

One .mrt file for different reports

Posted: Tue Feb 21, 2012 3:16 am
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.

One .mrt file for different reports

Posted: Wed Feb 22, 2012 6:59 am
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

One .mrt file for different reports

Posted: Thu Feb 23, 2012 9:12 am
by Alex K.
Hello,

Please send your sample which reproduces the issue for analysis.

Thank you.