我正在使用MySql数据库在C#.NET中创建应用程序。我正在创建报告,我的数据库中有“invoice_details”表,该表在MySql中创建。
我想在打印报告时打印Sr.No.
列。所以我在page_Load()
事件
至少我正在使用此代码完成所有步骤。我已经使用上面提到的列和它的数据集设计了报告文件。我还通过对话框将数据源添加到rdlc
报告文件中,并将rdlc
文件添加到MicrosoftReportViewer
。
现在的问题是 - 它会编译所有步骤和代码行而没有错误,但它仍然不会生成报告,只是默认退出。
我发布了下面的frmReport.cs文件代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
using Microsoft.Reporting.WinForms;
using System.IO;
namespace CeraAccount.Modules
{
public partial class frmReportViewer : Form
{
public int INVOICE_NO;
public frmReportViewer()
{
InitializeComponent();
}
private void frmReportViewer_Load(object sender, EventArgs e)
{
MySqlConnection conn;
MySqlCommand cmd;
MySqlDataReader dr;
//Report data source object define here
invoiceReportDataSource objDataSet = new invoiceReportDataSource();
try
{
conn = new MySqlConnection(Program.ConnectionString);
conn.Open();
cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM invoice_details";
dr = cmd.ExecuteReader();
int i = 1;
//Get selected record in seperate table object
while (dr.Read())
{
DataRow row = objDataSet.Tables["invoice_details"].NewRow();
row[0] = Convert.ToInt32(dr["id"].ToString());
row[1] = dr["invoice_no"].ToString();
row[2] = dr["description_of_goods"].ToString();
row[3] = dr["size"].ToString();
row[4] = dr["grade"].ToString();
row[5] = dr["quantity"].ToString();
row[6] = dr["max_retail_price"].ToString();
row[7] = dr["ass_rate_per_unit"].ToString();
row[8] = dr["total_ass_value"].ToString();
row[9] = dr["sale_price_per_unit"].ToString();
row[10] = dr["total_sale_value"].ToString();
row[11] = dr["created"].ToString();
row[12] = i;
objDataSet.Tables["invoice_details"].Rows.Add(row);
i++;
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
ReportDataSource rds = new ReportDataSource("objDataSet", objDataSet.Tables["invoice_Details"]);
this.rptViewer.LocalReport.EnableExternalImages = true;
this.rptViewer.LocalReport.EnableHyperlinks = true;
rptViewer.LocalReport.DataSources.Clear();
rptViewer.LocalReport.DataSources.Add(rds);
this.rptViewer.RefreshReport();
}
}
}
而且伙计们有多少没有。报告参数我们用一个报告文件添加?