VbNet2008 Crystal Report 9 problem
Hi Good Guys, :wave:
I need your help. Please help me. :blush:
While developing VBNet2008 Window Application to automate Crystal Report printing I encountered this error message : "THIS VALUE IS WRITE ONLY"
On the vbnet FORM, crystal report viewer object was embedded to allow the user to view the report prior to printing it. The crystal Report control, AxCrystalActiveXReportViewer1 was obtained from the ToolBox like all VbNet controls.
This is the coding
Code:
Option Explicit On
Imports System.Data.SqlClient
Imports System.Data
Imports System.Drawing
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.shared
Imports CrystalDecisions.Windows.Forms
Public Class FrnTextCryReportViewer
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Try
Dim cryfolder As String = "F:\VbNet2008CrystalReport\ CrystalReportOrderDetails.rpt"
Dim cryRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
cryRpt.Load(cryfolder)
With Me.AxCrystalActiveXReportViewer1
.ReportSource = cryRpt <--- generate error "This value is Write-only "
.Refresh()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thank you. :D
Have a Good Day. :)
Cheers,
Lennie
Re: VbNet2008 Crystal Report 9 problem
I am using code like the following to view Crystal Reports from .Net
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim oApp = New CRAXDRT.Application
Dim oReport As CRAXDRT.Report
oReport = oApp.OpenReport("C:\temp\reportname.R01.rpt", 1)
With oReport.Database.Tables(1).ConnectionProperties
.DeleteAll()
.Add("Provider", "SQLOLEDB.1")
.Add("User ID", "UserName")
.Add("Password", "Password")
.Add("Initial Catalog", "Database")
.Add("DSN", "DSNName")
End With
AxCrystalActiveXReportViewer1.ReportSource = oReport
AxCrystalActiveXReportViewer1.ViewReport()
End Sub
Private Sub AxCrystalActiveXReportViewer1_Enter(sender As System.Object, e As System.EventArgs) Handles AxCrystalActiveXReportViewer1.Enter
End Sub
End Class
Re: VbNet2008 Crystal Report 9 problem
Try:
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Dim RptDoc As New ReportDocument()
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim crtableLogoninfo As New TableLogOnInfo
RptDoc.Load(Server.MapPath(Request.ApplicationPath + "/Reports/myReport.rpt"))
With crConnectionInfo
.ServerName = "myServer"
.DatabaseName = "myDatabase"
.UserID = "myUserID"
.Password = "myPassword"
End With
CrTables = RptDoc.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
RptDoc.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.ServerName)
RptDoc.SetParameterValue("@myParameter", myValue)
Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & myDownloadAsFilename)
Response.AddHeader("content-length", stream.BaseStream.Length.ToString())
Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
Response.Flush()
Response.Close()
Re: VbNet2008 Crystal Report 9 problem
I don't think you should be using AxCrystalActiveReportViewer in VB .Net. You should be using CrystalReportViewer component for VB .Net. Read this http://scn.sap.com/thread/2131910