Hi there.
Could someone show me in C# how to set a reports datasource to a mssql server and database programmatically, please?
Regards
Renier
Setting datasource programmatically
Setting datasource programmatically
Hello,
1. Use DataSet
2. Use SqlSorce
Design:
Thank you.
1. Use DataSet
Code: Select all
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand myCommand = new SqlCommand("SELECT * FROM PRODUCTS", connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(myCommand);
DataSet dataSet = new DataSet("DataBase");
dataAdapter.Fill(dataSet);
StiReport stiReport = new StiReport();
stiReport.RegData(dataSet);
stiReport.Design();
}
Design:
Code: Select all
Stimulsoft.Report.Dictionary.StiSqlDatabase db = new Stimulsoft.Report.Dictionary.StiSqlDatabase("test", "");
db.ConnectionString = connectionString;
Stimulsoft.Report.Dictionary.StiSqlSource userSource = new Stimulsoft.Report.Dictionary.StiSqlSource();
userSource.NameInSource = "test";
userSource.Alias = "PRODUCTS";
userSource.Name = "PRODUCTS";
userSource.SqlCommand = "SELECT * FROM PRODUCTS";
StiReport stiReport = new StiReport();
stiReport.Dictionary.Databases.Add(db);
stiReport.Dictionary.DataSources.Add(userSource);
stiReport.Dictionary.Synchronize();
stiReport.Design();
Show:
StiReport stiReport = new StiReport();
stiReport.Load(@"D:\Report.mrt");
stiReport.Show();