发布时间 : 2015-12-08 10:16:40.000|阅读 3224 次
概述:这部分主要提供一些Stimulsoft Reports.Net中开发者在数据连接时常遇到的问题及解决方案。
相关链接:
这部分主要提供一些在Stimulsoft Reports.Net中,开发者在数据连接时常遇到的问题及解决方案。
< 立即下载Stimulsoft Reports.Net v2018.2.3最新版本>
在渲染报表前使用以下代码:
C#
//清除数据库列表 report.Dictionary.Databases.Clear(); //添加数据库并指定其名称和连接字符串 report.Dictionary.Databases.Add(new StiSqlDatabase("Test", "MyDataConnectionString"));
VB
'清除数据库列表 Report.Dictionary.Databases.Clear() '添加数据库并指定其名称和连接字符串 Report.Dictionary.Databases.Add(new StiSqlDatabase("Test", "MyDataConnectionString"))
使用数据源索引器。示例:
C#
object data = Customers["Phone"];
VB
Dim Data As Object = Customers("Phone")
你可以使用报表参数来实现。默认情况下报表引擎不支持将参数作为一个标准的查询点。例如下面这个查询语句:
select * from customers where code = :code
在这种情况下你无法检测:code的值。然而你可以使用链接到报表变量的表达式形成SQL查询的任何一部分。例如:
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
如果所有的数据都被同一个报表采集,如果你使用SQL查询,那就没必要使用RegData方法。
你需要在数据源中创建一个参数,在SQL查询中写入:
select * from customers where customerid=@customerid
然后初始化该参数。在代码中初始化方法如下:
C#
StiReport report = new StiReport(); report.RegData(myDataset); report.Compile(); report["@customerid"] = 1;
VB
Dim Report As StiReport = New StiReport() Report.RegData(MyDataSet) Report.Item("@customerid") = 1
首先在服务器上生成报表,并将渲染的报表保存到流中:
C#
StiReport report = new StiReport(); report.RegData(dataSet); report.Render(false); report.SaveDocument(stream);
VB
Dim Stream As New MemoryStream Dim Report As New StiReport Report.RegData(DataSet) Report.Render(False) Report.SaveDocument(Stream)
在客户端从流中加载渲染后的报表并设置以下数据:
C#
StiReport report = new StiReport(); report.LoadDocument(stream); report.Show();
VB
Dim Report As New StiReport Report.LoadDocument(stream) Report.Show()
实现方法很多,如下:
使用属性
使用事件
Image1.Image = Image.FromFile("Image1.gif");
Image1.Image = Stimulsoft.Base.Drawing.StiImageFromURL.LoadBitmap( "http://www.domain.com/bitmap.gif");
可以使用以下代码实现:
C#
StiReport report = new StiReport(); report.Load("MyReport.mrt"); report.Dictionary.Databases.Clear(); report.Dictionary.Databases.Add(new StiSqlDatabase("MyDatabase", "new connection string"));
VB
Dim Report As New StiReport Report.Load("MyReport.mrt") Report.Dictionary.Databases.Clear() Report.Dictionary.Databases.Add(New StiSqlDatabase("MyDatabase", "new connection string"))
你可以使用表达式形成SQL查询的任何部分。首先,在报表字典里创建一个变量,然后将该变量添加到SQL查询中:
select * from customers where code = {myvariable}
最后,在运行报表前初始化该变量:
C#
StiReport report = new StiReport(); rreport.Load("Variables.mrt"); report.Compile(); //设置变量 report["myvariable"] = 123; report.Render();
VB
Dim Report As StiReport = New StiReport() Report.Load("Variables.mrt") Report.Compile() '设置变量 Report.Item("myvariable") = " Value " Report.Render()
你可以在GetValueEvent中使用以下代码来实现:
C#
if (Customers["Flag"] == null)e.Value = "YES"; else e.Value = "NO";
VB
If (Customers("Flag") Is Nothing) Then e.Value = "YES" Else e.Value = "NO" End If
使用IIF函数也同样可以实现:
C#
{IIF(Customers["Flag"] == null, "YES", "NO")}
VB
{IIF(Customers("Flag") Is Nothing, "YES", "NO")}
这种情况下你需要将所有数据缓存到一个DataSet里。在报表字典里将CacheAllData属性值设置为true即可实现。
购买最新正版授权!详情请"咨询在线客服"