原創|使用教程|編輯:鄭恭琳|2015-12-08 10:16:40.000|閱讀 3332 次
概述:這部分主要提供一些Stimulsoft Reports.Net中開發者在數據連接時常遇到的問題及解決方案。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
這部分主要提供一些在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( "//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即可實現。
購買最新正版授權!詳情請""
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn