Crystal Reports is not showing records from the database, only the columns(Crystal Reports 不显示数据库中的记录,只显示列)
问题描述
我正在尝试显示数据库中创建的其中一个表中的记录.当我运行应用程序时,它会加载,但我只能看到没有记录的列(记录存在).在我的设计模式中,我放置了 CrystalReportViewer,并创建了 CrystalReport 的源代码.
我正在使用 VS 2015 和 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="服务器"><标题></标题><script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js"></script></头><身体><form id="form1" runat="server"><CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl=""Height="1202px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelView="None" ToolPanelWidth="200px" Width=1104 像素"/><CR:CrystalReportSource ID="CrystalReportSource1" runat="server"><报告文件名="CrystalReport2.rpt"></报告></CR:CrystalReportSource></div></表格></身体></html>
在我的 .cs 中,我有上面的代码.我的桌子叫 Salarii
使用系统;使用 System.Collections.Generic;使用 System.Data;使用 System.Configuration;使用 System.Data.SqlClient;使用 CrystalDecisions.CrystalReports.Engine;公共部分类 WebForm : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){ReportDocument 水晶报告 = new ReportDocument();crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));DataSet dsSalarii = GetData("select * from Salarii");水晶报告.SetDataSource(dsSalarii);CrystalReportViewer1.ReportSource = 水晶报告;}私有数据集GetData(字符串查询){字符串 conString = ConfigurationManager.ConnectionStrings["MyDbConnectionString"].ConnectionString;SqlCommand cmd = 新 SqlCommand(查询);使用 (SqlConnection con = new SqlConnection(conString)){使用 (SqlDataAdapter sda = new SqlDataAdapter()){cmd.Connection = con;sda.SelectCommand = cmd;使用 (DataSet dsSalarii = new DataSet()){sda.Fill(dsSalarii, "DataTable1");返回dsSalarii;}}}}}
我对此很陌生,并且在开发过程中遵循了教程.我需要帮助,这是学校里一个非常重要的项目,我会很感激我能得到的每一个帮助.
- 尝试一步一步调试.. 你的 dsSalarii 有一些数据吗?如果是,请进行下一步
- 您必须确保DataTable的名称(在您的情况下为DataTable1")与CrystalReport中的名称相同,如果是,请进行下一步
仅将DataSource设置为报表是不够的,必须将数据传递给报表:
ds.WriteXml(XmlDataPath)
将您的数据集保存为 xml,现在您可以将生成的 xml 添加到 Crystal Report,因此打开 Crystal Report,转到 Database> Database Expert> Create New Connection> ADO.NET(xml) 并选择生成 xml 的路径
下一步是将数据库字段放入报告中
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.
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>
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.
- Try to debug, step by step.. does your dsSalarii has some data? if yes, go next step
- You must to ensure, that name of DataTable (in your case : "DataTable1") is the same in CrystalReport, if yes, go next step
It s not enough to only Set DataSource to a report, you must pass data to a report :
ds.WriteXml(XmlDataPath)
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 不显示数据库中的记录,只显示列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Crystal Reports 不显示数据库中的记录,只显示列
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01