Stimulsoft Reports.Net报表控件在数据存取上的常见问题

作者:控件中国网   出处:控件中国网   2015-08-17 14:51:19   阅读:9

Stimulsoft Reports.Net报表控件对数据存取、数据操作上极其简单,下面咱们就列举出报表数据存取上的常见问题:

1.怎么改变数据库链接?
//Clear the list of databases
report.Dictionary.Databases.Clear();
//Add the database and specify its name and the connection string
report.Dictionary.Databases.Add(new StiSqlDatabase("Test",
"MyDataConnectionString"));
2.当报表呈现时如何改变数据库查询文本?
select * from customers where code = {myvariable}
select * from customers where {myvariable}
select * from customers {myvariable}
select * from {myvariable} where code=1
select {myvariable} from customers where code = {myvariable}
{myvariable}
select * from customers where code = {MyStaticClass.GetCondition()}
select * from customers where {Datasource.Condition}
select {myvar+myvar2} from customers
上面查询语句中的code不能删除
3.怎么添加一个变量到SQL查询语句里
在数据源,查询语句里里首先应该创建一个变量
select * from customers where customerid=@customerid
然后在代码里初始化该变量
StiReport report = new StiReport();
report.RegData(myDataset);
report.Compile();
report["@customerid"] = 1;

4.怎么在服务器上呈现一个报表并发送到客户端?
StiReport report = new StiReport();
report.RegData(dataSet);
report.Render(false);
report.SaveDocument(stream);

然后在客户端加载报表
StiReport report = new StiReport();
report.LoadDocument(stream);
report.Show();

5.怎么在运行时改变报表的数据库链接?
StiReport report = new StiReport();
report.Load("MyReport.mrt");
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase("MyDatabase", "new connection string"));
6.怎么从应用程序发送变量到SQL查询语句中?
首先添加变量到SQL查询语句如下:
select * from customers where code = {myvariable}
其次在代码里对变量进行初始化:
StiReport report = new StiReport();
rreport.Load("Variables.mrt");
report.Compile();
//Set Variable
report["myvariable"] = 123;
report.Render();

7.怎么检测空值?
在GetValueEvent事件中使用下面的代码:
if (Customers["Flag"] == null)e.Value = "YES";
else e.Value = "NO";
 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat