水晶報表 Crystal Report 調用預存程序時出錯 找不到表 ,解決方案。,crystalreport
用 CrystalReportViewer1 控制項在asp.net的網頁上顯示報表,如果做報表時調用資料表資料的方式調用是可以成功的,但報表是用預存程序擷取資料方式會出現以下錯誤:
找不到表'RptOpenCheck;1' 。 檔案 G:\TEMP\FO-OpenCheck {6D191F06-DECF-4A25-88FC-8553E3D435AA}.rpt 內出錯: 找不到表。
Error: 未將對象引用設定到對象的執行個體。
The table 'RptOpenCheck;1' could not be found. Error in File G:\TEMP\FO-OpenCheck {6D191F06-DECF-4A25-88FC-8553E3D435AA}.rpt: The table could not be found.
未能開啟該串連。 未能開啟該串連。 G:\TEMP\FO-OpenCheck {4E60249E-FC16-4F3D-A610-138FC3297171}.rpt
VS2005 環境,Crsytal Reports 11.5
代碼以下:
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crParameterFields As ParameterFields
Dim crParameterField As ParameterField
Dim crParameterValues As ParameterValues
Dim crParameterDefValues As ParameterValues
Dim crParameterValue As ParameterValue
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim CrTables As Tables
Dim CrTable As Table
Dim ReportName As String
Dim PrintTo As String ' P Printer V Window
Dim ReportPath As String
Dim UserName As String
Dim Password As String
Dim ServerName As String
Dim DatabaseName As String
Dim crReportDocument As New ReportDocument
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
Dim strParam As String = Request("p")
'擷取使用者請求參數
If Right(strParam, 1) = "~" Then
strParam = Mid(strParam, 1, Len(strParam) - 1)
End If
'參數轉換為數組
s = Split(strParam, "~")
'use odbc connection database
With crConnectionInfo
.AllowCustomConnection = True
.ServerName = ”ODBCName"
'.DatabaseName = "TempDB"
.UserID = "sa"
.Password = "Microwin"
End With
''use SQL connection database
'With crConnectionInfo
' .AllowCustomConnection = True
' .ServerName = "(local)"
' .DatabaseName = "TempDB"
' .UserID = "sa"
' .Password = "Microwin"
'End With
'指定報表路徑
ReportPath = Server.MapPath(Request.ApplicationPath)
ReportNamePath = ReportPath & "\testing.rpt"
'check report file exists and Load Report
If System.IO.File.Exists(ReportNamePath) Then
crReportDocument.Load(ReportNamePath)
End If
'設定報表文檔給報表控制項
Me.CrystalReportViewer1.ReportSource = crReportDocument
'設定串連資料庫資訊給報表文檔
CrTables = crReportDocument.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
'就是這句沒有加,所以會出現以上錯誤資訊,只有報表是調用預存程序取資料時才會出現錯誤。花了我幾天時間,終於解決了。
CrTable.Location = CrTable.Name
Next
'設定控制項顯示的屬性
With CrystalReportViewer1
.AutoDataBind = True
.ReuseParameterValuesOnRefresh = True
.EnableDatabaseLogonPrompt = False
.EnableParameterPrompt = False
CrystalReportViewer1.DisplayGroupTree = False
CrystalReportViewer1.DisplayPage = True
CrystalReportViewer1.DisplayToolbar = True
CrystalReportViewer1.ReportSource = crReportDocument
End With
If Not IsPostBack Then
'取使用者請求的參數賦值給報表,如果報表需要參數的話,從第三個元素開始為報表參數值。
crParameterFields = Nothing
crParameterFields = CrystalReportViewer1.ParameterFieldInfo
Dim j As Integer = UBound(s, 1)
For i = 0 To crParameterFields.Count - 1
crParameterField = crParameterFields.Item(i)
crParameterValues = crParameterField.CurrentValues
crParameterDefValues = Nothing
crParameterDefValues = New ParameterValues
crParameterDefValues = crParameterField.DefaultValues
crParameterDiscreteValue = Nothing
crParameterDiscreteValue = New ParameterDiscreteValue
If i > (j - 2) Then
Select Case crParameterField.ParameterValueKind
Case ParameterValueKind.BooleanParameter
crParameterDiscreteValue.Value = False
Case ParameterValueKind.CurrencyParameter
crParameterDiscreteValue.Value = Nothing
Case ParameterValueKind.DateParameter
crParameterDiscreteValue.Value = System.DateTime.Now
Case ParameterValueKind.DateTimeParameter
crParameterDiscreteValue.Value = System.DateTime.Now
Case ParameterValueKind.NumberParameter
crParameterDiscreteValue.Value = Nothing
Case ParameterValueKind.StringParameter
crParameterDiscreteValue.Value = " "
Case ParameterValueKind.TimeParameter
crParameterDiscreteValue.Value = System.DateTime.Now
End Select
crParameterValues.Add(crParameterDiscreteValue)
Else
Select Case crParameterField.ParameterValueKind
Case ParameterValueKind.BooleanParameter
crParameterDiscreteValue.Value = IIf(s(i + 2) = "0", False, True)
Case ParameterValueKind.CurrencyParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", Nothing, s(i + 2))
Case ParameterValueKind.DateParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", Nothing, s(i + 2))
Case ParameterValueKind.DateTimeParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", Nothing, s(i + 2))
Case ParameterValueKind.NumberParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", Nothing, s(i + 2))
Case ParameterValueKind.StringParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", " ", s(i + 2))
Case ParameterValueKind.TimeParameter
crParameterDiscreteValue.Value = IIf(Trim(s(i + 2) & "") = "", Nothing, s(i + 2))
End Select
crParameterValues.Add(crParameterDiscreteValue)
End If
Next
End If
End Sub
C# 中crystal report水晶報表的PDF顯示問題
不是pdf的事,是水晶報表設定的原因,大概原因如下:
原因1:CR輸出的漢字格式不對(簡體還是繁體),簡體要先在地區設成(中國),然後在cr裡設字型為"宋體“即可
原因2:字元集問題。應查看web.config中字元集配置
原因3:資料流量過大。有時候,在水晶報表中匯入的資料過多,並配置有圖表,而伺服器的配置相對較低,那麼程式運行並不會報錯,只是在顯示的頁面上顯示亂碼!至於原因,還沒有搞明白。
原因4:Crystal Report 8.5匯出的PDF是為亂碼,但CryStal Report 9.0已經修正了這個問題。那麼方法一是可以把Crystal Report8.5版本下做的報表重新在CryStal Report9.0再做,但如果所涉及的報表太多,那就很費力;方法二就是在打包CrySatl的安裝程式時,可以打包Crystal Report8.5的Runtime dll,而另個一個crviewer.dll則需要使用Crystal Report9.0版本的就可以解決這個問題,這種方法則比較簡單方便。補充說明,還有方法三,就是不需要作任何的更改,不用匯出的功能,使用Adode PDF Printer的列印功能去列印CP8.5的報表,通過列印功能輸入的PDF則不會亂碼。將Crystal Reports 9 版本下的crxf_pdf.dll覆蓋8.5版本下的同名檔案即可
原因5:針對顯示中文的FIELD採用中文字型.如"宋體 (CHINESE_GB2312)",請注意一定要選擇中文的字元集.選擇匯出到EXCEL5.0,EXCEL6.0或EXCLE7.0格式的檔案.切勿選擇EXCEL8.0格式.先將報表匯出為文字檔格式(如Tab-separated Text),再用EXCEL開啟並儲存.xls為檔案.
C# WinForm中水晶報表配置好了,用crystalReportViewer顯示怎只有欄位名,沒有看到資料
你沒填充資料怎麼會有資料,你在資料集裡拖出來的
表只是一個表結構
DataSet1 ds = new DataSet1();
using (SqlConnection conn = new SqlConnection(conString))
{
using (SqlDataAdapter adpt = new SqlDataAdapter("select * from MedicionType", conn))
{
adpt.Fill(ds, "表名,必須和你的資料集裡拖出來的一樣");
}
}
CrystalReport1 cys = new CrystalReport1();
cys.SetDataSource(ds);
this.crystalReportViewer1.ReportSource = cys;