Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET 2000 Crystal Reports first time attempt

Status
Not open for further replies.

RodolfoDallas

Programmer
Oct 25, 2006
1
US
I have spent the last three days trying to make a Crystal Report work on my WEB project.

I have created a project from scratch for testing purposes. Get the same errors as with the large project.

I have an SQL Database on my local computer. I have a Companies table in it. It is populated.
I created a Crystal Report from within the VB.NET environment using the expert called CrystalReport1.rpt.
Created a WebForm into which I added a CrystalReportViewer.
Added an SQLConnection, SQLDataAdapter and based on this last one, created a dataset dsCompanies1 in the webform.

This is the code behind of my form with commands manually added in red:
=========================================================
Imports CrystalDecisions.CrystalReports.Engine
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlConnection As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents DsCompanies1 As WebApplication1.dsCompanies
Public WithEvents oRpt As CrystalReport1
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization
oRpt = New CrystalReport1()
SqlConnection.ConnectionString = "Server=Srv01; Initial Catalog=MyCat; User Id=AppUser; Password=xxx;"
SqlConnection.Open()
SqlDataAdapter1.Fill(DsCompanies1)
oRpt.SetDataSource(DsCompanies1)

CrystalReportViewer1.DataBind()
CrystalReportViewer1.ReportSource = oRpt

oRpt.SetDataSource(DsCompanies1)

End Sub

Private Sub SqlConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs)

End Sub
End Class
=========================================================

If I bind the ReportViewer to the dsCompanies dataset from within the WebForm properties list, or to the physical file "C:\Inetpub\ or leave it unbound, I get the following on my web browser:

Object reference not set to an instance of an object.
Description:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


Source Error:

Line 238: oRpt.SetDataSource(DsCompanies1)
Line 239:
Line 240: CrystalReportViewer1.DataBind()

---------------------------------------------------------
Removing the command on line 240 gives me the same error, but on line 241:
Line 239:
Line 240: 'CrystalReportViewer1.DataBind()
Line 241: CrystalReportViewer1.ReportSource = oRpt

---------------------------------------------------------

If I DataBind the CrystalReportViewer1 to the name of the report, I get the following error:

Compiler Error Message: BC30451: Name 'CrystalReport1' is not declared.
Source Error:
Line 12: <body MS_POSITIONING="GridLayout">
Line 13: <form id="Form1" method="post" runat="server">
Line 14: <CR:CrystalReportViewer id="CrystalReportViewer1" style="Z-INDEX: 101; LEFT: 36px; POSITION: absolute; TOP: 26px" runat="server" Width="350px" Height="50px" ReportSource="<%# CrystalReport1.rpt %>">

------------------------------------------------------------

Following some advice, I right-clicked on the CrystalReport1.rpt and published it as a Web Service. No luck.

I have spent too long trying this thing to work and I am at the end of my rope. Any help will be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top