6. ASP.NET 程序在 Page_Load 事件里读取要排序的字段 sort_field,然后对水晶报表进行排序。
7. 水晶报表排序编程实例
Dim crReportDocument As ReportDocument
Public Sub changeSortField(mySortFld As String, mySortDir As String)
Dim crSortField As SortField
Dim crSortDirection As SortDirection
Dim crDatabaseFieldDefinition As DatabaseFieldDefinition
For Each crSortField In crReportDocument.DataDefinition.SortFields
If crSortField.Field.Name.ToString = mySortFld Then
crDatabaseFieldDefinition = crReportDocument.Database.Tables(0).Fields(mySortFld.ToString)
crSortField = crReportDocument.DataDefinition.SortFields(0)
crSortField.Field = crDatabaseFieldDefinition
If mySortDir = "Ascending" Then
crSortField.SortDirection = SortDirection.AscendingOrder
Else
crSortField.SortDirection = SortDirection.DescendingOrder
End If
End If
Next
CrystalReportViewer1.ReportSource = crReportDocument
End Sub
3、设置上述文件夹的“安全”,即 NTFS 权限:
最简单的办法是给 Everyone 用户加“完全控制”权限!
(1)为当前用户,如:Administrator,,添加“写入”权限;
(2)为用户 ASPNET、SYSTEM、匿名用户(通常为 IUSR_MACHINENAME)、经过身份验证的请求用户添加“写入”权限。
---------------------------------------------------------------
三、原因2:PULL 模式,水晶报表中的数据库登录问题。
运行时登录数据库服务器的方法(PULL 模式)
在报表的cs文件中,加上数据库连接。
1、设置 ReportDocument 的 TableLogonInfo……
Dim ReportDoc As New ReportDocument()
Dim logonInfo As New TableLogonInfo
Dim table As table
ReportDoc.Load("C:\Rpts\publish.rpt")
For Each table IN ReportDoc.DataBase.Tables
logonInfo= table.LogonInfo
with logonInfo.connectioninfo
.serverName= "Localhost"
.Databasename= "pubs"
.UserID= "sa"
.Password=""
End With
table.applyLogonInfo(logonInfo)
next table
Crviewer.reportsource = reportDoc
2、如果是多个相关的表作为报表的数据源,最好使用存储过程或者查询作为数据源。
3、将“数据库连接信息”存放在 web.config 配置文件,易维护。
using CrystalDecisions.Shared ; //负责解释TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine ; //负责解释ReportDocument类