Page 1 of 4

set datasource

Posted: Sat May 05, 2012 2:55 am
by roya
Hello
i want to set datasource of report in runtime,pleas help me to do it

set datasource

Posted: Mon May 07, 2012 5:42 am
by Alex K.
Hello,

You can use the RegData(DataSet) method or 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.

set datasource

Posted: Thu May 10, 2012 1:52 am
by roya
Thank you for your reply.
I dont want to create datasource on runtime,i want to set the datatable of datasource in runtime.i dont want to use select command on runtime.i have a datatable and want to append it to datasources datatable.please help me.

set datasource

Posted: Thu May 10, 2012 2:44 am
by HighAley
Hello.
roya wrote:Thank you for your reply.
I dont want to create datasource on runtime,i want to set the datatable of datasource in runtime.i dont want to use select command on runtime.i have a datatable and want to append it to datasources datatable.please help me.
If you have a datatable you should use RegData(string name, System.Data.DataTable dataTable) method.

Thank you.

set datasource

Posted: Tue May 29, 2012 4:57 am
by csbrogi
Hello,
I have a similar problem:
- I use one xml-file to design my report
- In a secound step I wantto use this report to create output from different datasource
my code is

Code: Select all

    dataSet1.ReadXmlSchema(schemaFile);
            dataSet1.ReadXml(xmlFile);
            
            //Add data to datastore
            
            StiReport report = new StiReport();

            report.Load(reportFile);
            
            report.RegData(dataSet1);            
            
            report.ShowWithWpf();
but allways the content from the datasource defined in reportFile is used.

How can I change the data file?

set datasource

Posted: Wed May 30, 2012 3:18 am
by Alex K.
Hello,

Please send us your report with test data for analysis.

Thank you.

set datasource

Posted: Wed May 30, 2012 4:54 am
by csbrogi
Hello
I attach the file
The report uses file TestFoo.xml as data-source and it's displaying "Foo"
in the csharp code I use Testbar.xml as data-source and this should display "Bar", but it also shows "Foo"

if you try the code, you only have to press "Build Report", the XSD and XML is hard-coded in this version.

Thank you
Clemens

set datasource

Posted: Thu May 31, 2012 4:03 am
by Alex K.
Hello,

Please check the folowing code:

Code: Select all

...
report.Load("TestFooBar.mrt");
report.Dictionary.Databases.Clear();
report.Dictionary.DataSources.Clear();
report.RegData(dataSet1);
report.Dictionary.Synchronize();
...
report.ShowWithWpf();
Thank you.

set datasource

Posted: Thu May 31, 2012 4:34 am
by csbrogi
Hello

in this case it works, but in a more complex I am running in an endless loop.

Code: Select all

 
        private string schemaFile = "C:\\temp\\birt\\Paket_Fachklasse_neu.xsd";

        private string xmlFile = "C:\\temp\\birt\\Paket_Fachklasse.xml";

        public Window1()
        {
            Stimulsoft.Report.Wpf.StiThemesHelper.LoadTheme(this);
            InitializeComponent();

            dataSet1.DataSetName = "Demo";
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dataSet1.ReadXmlSchema(schemaFile);
            dataSet1.ReadXml(xmlFile);

            //Add data to datastore

            StiReport report = new StiReport();

            report.Load("C:\\temp\\birt\\Crash.mrt");

            report.Dictionary.Databases.Clear();
            report.Dictionary.DataSources.Clear();
            report.RegData(dataSet1);
            report.Dictionary.Synchronize();
            report.ShowWithWpf();
        }
Thank you,
Clemens

set datasource

Posted: Thu May 31, 2012 5:01 am
by roya
Thank you for your reply
your suggestion worked and i used it , but if i have different datasources and i want to set the datatatables of them in runtim how can i determine them?
i shoulde write different RegData() ?