set datasource
Posted: Sat May 05, 2012 2:55 am
Hello
i want to set datasource of report in runtime,pleas help me to do it
i want to set datasource of report in runtime,pleas help me to do it
Reporting tool and data analytics tools for creating reports and dashboards in ASP.NET, ASP.NET MVC, .NET Core, Blazor, Angular, PHP, Python, WPF, JavaScript, and Java applications.
https://forum.stimulsoft.com/
Code: Select all
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Code: Select all
StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Code: Select all
foreach (DataColumn col in dataTableDS1.Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
Code: Select all
StiDataRelation dataRelation = new StiDataRelation("MyRelation", parentDS, childDS, new string[] { "Field" }, new string[] { "Field" });
report.Dictionary.RegRelations();
report.Dictionary.Relations.Add(dataRelation);
If you have a datatable you should use RegData(string name, System.Data.DataTable dataTable) method.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.
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();
Code: Select all
...
report.Load("TestFooBar.mrt");
report.Dictionary.Databases.Clear();
report.Dictionary.DataSources.Clear();
report.RegData(dataSet1);
report.Dictionary.Synchronize();
...
report.ShowWithWpf();
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();
}