Crystal Reports SetDataSource无法正常工作 [英] Crystal Reports SetDataSource not working

查看:113
本文介绍了Crystal Reports SetDataSource无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据源连接到Crystal Report,但是我得到的SetDataSource不是EmployeeReportView的一部分

我做错了什么?

这是我的ASP代码:

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:

<%@ 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>




这是VB.Net代码





Here is the VB.Net code


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

推荐答案

发现我的错误,我将报告设置为数据集而不是报告.还使SQL有点乱序.
Found my error I had the report set to a DataSet and not the report. Also Had the SQL a little out order.


VB中的代码

Codes in 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


这篇关于Crystal Reports SetDataSource无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆