Click here to Skip to main content
15,915,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to get the datasource connected to a Crystal Report but I get an SetDataSource is not a part of EmployeeReportView

What am I doing wrong?

Here is my ASP code:
XML
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="EmployeeReportView.aspx.vb" Inherits="PKL_QMW.EmployeeReportView" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
    AutoDataBind="True" EnableDatabaseLogonPrompt="False"
        GroupTreeImagesFolderUrl="" Height="962px"
        ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl=""
        ToolPanelView="None" ToolPanelWidth="200px" Width="1344px" />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server"  >
        <Report FileName="EmployeeOsha.rpt" >
        </Report>
    </CR:CrystalReportSource>

</asp:Content>



Here is the VB.Net code


VB
Public Class EmployeeReportView
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim rpt As New EmployeeReportView 'The report you created.

        Dim myConnection As SqlConnection
        Dim MyCommand As New SqlCommand()
        Dim myDA As New SqlDataAdapter()
        Dim myDS As New DataSet("EmployeeOshaDataSet")
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        MyCommand.Connection = myConnection
        MyCommand.CommandText = "SELECT zEdits.LastName + ', ' + zEdits.FirstName + ISNULL(zEdits.MI, '') AS Name, tblOSHA.ID, zEdits.SubWorkArea, zEdits.Site, tblOSHA.PID, zEdits.WorkArea, " & _
        " tblOSHA.ItemNumber, tblOSHA.Item, tblOSHA.DateQualified, tblOSHA.Reoccurrence, tblOSHA.Remarks, tblOSHA.QualifiedBy, tblOSHA.[Update], tblOSHA.Updatedby, " & _
        " tblOSHA.due FROM tblOSHA INNER JOIN zEdits ON tblOSHA.PID = zEdits.ID ORDER BY Name"
        MyCommand.CommandType = CommandType.Text
        myDA.SelectCommand = MyCommand
        myDA.Fill(myDS, "tblOSHA")
        rpt.MapPath("EmployeeOsha.rpt")
        rpt.SetDataSource(myDS)
        CrystalReportViewer1.ReportSource = rpt



    End Sub
Posted

Found my error I had the report set to a DataSet and not the report. Also Had the SQL a little out order.
 
Share this answer
 
Comments
Tech Code Freak 19-Jan-12 8:27am    
Great to solve it yourself!
Codes in VB

VB
Dim dt As New DataTable()
dt = [Module].fillgridProject()
Try
	If dt.Rows.Count > 0 Then
		Dim rptdoc As New ReportDocument()
		rptdoc.Load(Server.MapPath("~\Reports\ModuleReport.rpt"))
		rptdoc.SetDataSource(dt)
		'crv.ReportSource = rptdoc;
		'crv.DataBind();
		Dim exportOpts1 As ExportOptions = rptdoc.ExportOptions
		rptdoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
		rptdoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
		rptdoc.ExportOptions.DestinationOptions = New DiskFileDestinationOptions()
		DirectCast(rptdoc.ExportOptions.DestinationOptions, DiskFileDestinationOptions).DiskFileName = Server.MapPath("ProjectReport.pdf")
		rptdoc.Export()
		rptdoc.Close()
		rptdoc.Dispose()
		Response.ClearContent()
		Response.ClearHeaders()
		Response.ContentType = "application/pdf"
		Response.AppendHeader("Content-Disposition", "attachment; filename=ProjectReport.pdf")
		Response.WriteFile("ProjectReport.pdf")
		Response.Flush()
		Response.Close()
		System.IO.File.Delete(Server.MapPath("ProjectReport.pdf"))
	Else
		Messagebox1.Show("No Record for this District")
	End If
Catch
	Page.ClientScript.RegisterStartupScript(Me.[GetType](), "Hello", "javascript:alert('No Data Present');", True)
End Try
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 19-Jan-12 6:09am    
Added pre tag
Andy Morris 19-Jan-12 9:23am    
I'll give the above a try. I am getting another strange error though. I get Data Base Error when viewing the report.
Prashant Srivastava LKO 20-Jan-12 5:56am    
hi Andy

please remove the comments and add crystal Report viewer on your page and use two assemblies that is shown below:-
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

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