Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a Crystal Report with a dynamic data source. When i click the report button, the crystal report shows up just fine, but when i click any button the Crystal Report tool bar (i.e. Next page, Export To, etc.), i get a pop with the Error "No valid report source is available."
My Report viewer coding:

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpApplication
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports CrystalDecisions.ReportSource

Partial Class Reportviewer
Inherits System.Web.UI.Page
Public str As String
Public rptname As String
Public sf As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
Dim printModeList As ArrayList = New ArrayList()
printModeList.Add("ActiveX")
Dim con As New ConnectionInfo
Dim con1 As New ConnectionInfo
Dim db1 As Database
Dim dbs As Tables
Dim db As Table
Dim tab As TableLogOnInfo
rptname = Session("rptname")
str = Convert.ToString(Session("Str")) '"
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument

With con
.UserID = "sa"
.Password = "sa"
.DatabaseName = "TASHEEL"
' .ServerName = "Develope-PC"
.ServerName = "TASHEEL"

End With
If rptname = "inv_rep.rpt" Then
rpt.Load(Server.MapPath("..\Report\CrystalReport.rpt"))
End If
db1 = rpt.Database
dbs = db1.Tables
For Each db In dbs
tab = db.LogOnInfo
tab.ConnectionInfo = con
db.ApplyLogOnInfo(tab)
Next
CrystalReportViewer1.SelectionFormula = str
'rptname = Session("rptname") '"INV_LIST.rpt"
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.ShowFirstPage()
'CrystalReportViewer1.RefreshReport()
Session("Str") = ""
Session("rptname") = ""

End If
End Sub

End Class
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900