Crystal Reports不显示数据库中的记录,仅显示列 [英] Crystal Reports is not showing records from the database, only the columns

查看:82
本文介绍了Crystal Reports不显示数据库中的记录,仅显示列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示数据库中创建的表之一的记录.当我运行该应用程序时,它会加载,但是我只能看到没有记录的列(记录存在). 在我的设计模式下,我已放置CrystalReportViewer,并创建了CrystalReport的源.

I am trying to display the records from one of the tables created in a database. When I run the application, it loads but I can only see the columns without the records ( records exists). In my design mode I have placed CrystalReportViewer having the source of the CrystalReport created.

我正在将VS 2015与CrystalReports v 13.0.8一起使用

I am using VS 2015 with CrystalReports v 13.0.8

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm.aspx.cs" Inherits="WebForm" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="1202px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelView="None" ToolPanelWidth="200px" Width="1104px" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CrystalReport2.rpt">
            </Report>
        </CR:CrystalReportSource>
    </div>
    </form>
</body>
</html>

在我的.cs中,我具有上面的代码.我的桌子叫做Salarii

In my .cs I have the code above. My table is called Salarii

using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;

public partial class WebForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
        DataSet dsSalarii = GetData("select * from Salarii");
        crystalReport.SetDataSource(dsSalarii);
        CrystalReportViewer1.ReportSource = crystalReport;
    }

     private DataSet GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["MyDbConnectionString"].ConnectionString;              
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;

                sda.SelectCommand = cmd;
                using (DataSet dsSalarii = new DataSet())
                {
                    sda.Fill(dsSalarii, "DataTable1");
                    return dsSalarii;
                }
            }
        }
    }


}

我对此很陌生,在开发过程中遵循了教程.我需要帮助,这在学校是一个非常重要的项目,感谢我能获得的所有帮助.

I am very new to this and followed tutorials during the developing. I need help, this is a very important project at school and would appreciate every help I can get.

推荐答案

  1. 尝试逐步调试..您的dsSalarii是否有一些数据?如果是,请继续
  2. 您必须确保CrystalReport中的DataTable名称(在您的情况下为"DataTable1")相同,如果是,请继续执行
  3. 仅将数据源设置为报表是不够的,您必须将数据传递给报表:

  1. Try to debug, step by step.. does your dsSalarii has some data? if yes, go next step
  2. You must to ensure, that name of DataTable (in your case : "DataTable1") is the same in CrystalReport, if yes, go next step
  3. It s not enough to only Set DataSource to a report, you must pass data to a report :

ds.WriteXml(XmlDataPath)

将数据集另存为xml,现在您可以将生成的xml添加到Crystal报表中,因此打开Crystal报表,转到数据库">数据库专家">创建新连接"> ADO.NET(xml)并选择生成的xml的路径

save your dataset as xml, now you can add your generated xml to a Crystal Report, so open Crystal Report, go to Database> Database expert> Create New Connection> ADO.NET(xml) and choose path to generated xml

下一步是将数据库字段放入报告中

next step is putting database fields in report

这篇关于Crystal Reports不显示数据库中的记录,仅显示列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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