set datasource

Stimulsoft Ultimate discussion
roya
Posts: 4
Joined: Sat May 05, 2012 2:30 am

set datasource

Post by roya »

Hello
i want to set datasource of report in runtime,pleas help me to do it
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

set datasource

Post 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.
roya
Posts: 4
Joined: Sat May 05, 2012 2:30 am

set datasource

Post 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.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

set datasource

Post 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.
csbrogi
Posts: 89
Joined: Thu May 03, 2012 11:47 am
Location: Germany

set datasource

Post 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?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

set datasource

Post by Alex K. »

Hello,

Please send us your report with test data for analysis.

Thank you.
csbrogi
Posts: 89
Joined: Thu May 03, 2012 11:47 am
Location: Germany

set datasource

Post 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
Attachments

[The extension xaml has been deactivated and can no longer be displayed.]

1885.Window1.xaml.cs
(3.46 KiB) Downloaded 629 times
1884.TestBar.xml
(221 Bytes) Downloaded 439 times
1883.TestFoo.xml
(221 Bytes) Downloaded 434 times
1882.TestFooBar.xsd
(1.1 KiB) Downloaded 424 times
1881.TestFooBar.mrt
(6.2 KiB) Downloaded 675 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

set datasource

Post 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.
csbrogi
Posts: 89
Joined: Thu May 03, 2012 11:47 am
Location: Germany

set datasource

Post 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
Attachments
1898.Paket_Fachklasse.xml
(121.51 KiB) Downloaded 449 times
1897.Paket_Fachklasse_neu.xsd
(7.31 KiB) Downloaded 442 times
1896.Crash.mrt
(34.52 KiB) Downloaded 456 times
roya
Posts: 4
Joined: Sat May 05, 2012 2:30 am

set datasource

Post 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() ?
Post Reply