- PR -

CrystalReportサブレポートの参照db変更方法

1
投稿者投稿内容
dsr3
会議室デビュー日: 2003/03/22
投稿数: 1
投稿日時: 2003-03-22 11:14
初めまして、困ったときにいつも助けられています。

今回はCrystalReportのサブレポートで悩んでおります。
サブレポートを使うと「ログオンに失敗しました。」
というエラーになってしまいます。
メイン側のdbは変更できたのですが、
サブレポートの参照db変更方法がわかりません。
どなたかご教授よろしくお願いします。

ASP.NET(VB)、.NET付属のCrystalReportsを使用
現在は下記のように記述しております

Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

Dim rptExpensiveProducts As New ReportDocument()

rptExpensiveProducts.Load("path\レポート名.rpt")

For Each tbCurrent In rptExpensiveProducts.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = "サーバー名"
.UserID = "ID"
.Password = "Pass"
.DatabaseName = "db"
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent

CrystalReportViewer1.ReportSource = rptExpensiveProducts
Nag
会議室デビュー日: 2004/06/29
投稿数: 5
投稿日時: 2004-09-21 01:32
教えていただき、ありがとうございます。
早速試してみたのですが、上手くいきませんでした。
結果としてサーバにエクスポートされたPDFファイルには得意先マスタの内容が全件出力されています。
@ソースが問題なのでしょうか?(データセットには対照分のデータのみセットされています。)
ACrystalReport側のデータベースフィールドが設定してあるのが問題なのでしょうか?
度々、申訳ありませんが、よろしくお願いいたします。
*************************************************************************************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim crDoc As New ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim Fname As String ' ファイル名

Dim daReport As SqlDataAdapter
Dim dsReport As DataSet
Dim SQLStr As String
Dim strTableName As String
Dim m_SQLStr As String
Dim connectionString As String = CType(ConfigurationSettings.AppSettings("SQLCon"), String)
Dim conReport As SqlConnection = New SqlConnection(connectionString)

Dim logOnInfo As New TableLogOnInfo
' レポート内のテーブルの接続情報を設定します。
logOnInfo.ConnectionInfo.ServerName = "○○○"
logOnInfo.ConnectionInfo.DatabaseName = "×××"
logOnInfo.ConnectionInfo.UserID = "△△△"
logOnInfo.ConnectionInfo.Password = ""
logOnInfo.TableName = "MST_TOKUISAKI"

crDoc.Load("c:\inetpub\wwwroot\WebApplication3\CrystalReport1.rpt")
m_SQLStr = "select * from MST_TOKUISAKI WHERE TokuisakiCd='150120'"

If m_SQLStr <> "" Then
daReport = New SqlDataAdapter(m_SQLStr, conReport)
dsReport = New DataSet

conReport.Open()
daReport.Fill(dsReport, "MST_TOKUISAKI")

conReport.Close()
crDoc.SetDataSource(dsReport)
End If
' サーバへエクスポート
Fname = "c:\exports\" & Page.Session.SessionID().ToString & ".pdf"
crDiskFileDestinationOptions = New DiskFileDestinationOptions
crDiskFileDestinationOptions.DiskFileName = Fname
crExportOptions = crDoc.ExportOptions
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
crDoc.Export()
End Sub
*************************************************************************************************
Nag
会議室デビュー日: 2004/06/29
投稿数: 5
投稿日時: 2004-09-21 01:45
スレッド違いの所に返信してしまいました.
申訳ありません。ご迷惑をおかけしました.
以後、気をつけます。
1

スキルアップ/キャリアアップ(JOB@IT)