使用Microsoft Report Viewer中的DataTables中的数据 [英] Using data in DataTables in Microsoft Report Viewer

查看:51
本文介绍了使用Microsoft Report Viewer中的DataTables中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我遇到了一个我自己无法解决的问题。



我有一个Windows窗体( RepF ),其中包含一个Microsoft Report Viewer( Report1.rdlc )组件。



另外,我有另一个Windows表格(校长),我填写有关发票的信息,系统自动生成此发票的编号并将其插入数据库(MySQL)。



当我点击将这些信息存储到数据库中的按钮时,系统向我显示一个窗口,询问我是否要打印它。如果单击,系统将打开Windows窗体 RepF ,将发票号作为参数发送到此Windows窗体构造函数。



Hi all,

I''ve got a problem which I can''t solve by myself.

I have a Windows Form (RepF) which contains a Microsoft Report Viewer (Report1.rdlc) component.

Also, I have another Windows Form (Principal) where I fill in the information about the invoice, the system automatically generates the number of this invoice and insert it into the database (MySQL).

When I click over the button that stores these information into the database, the system shows me a window asking me if I want to print it. If I click YES, the system opens the Windows Form RepF, sending the invoice number as a parameter to this Windows Form constructor.

public RepF(string invoiceNumber)
{
    InitializeComponent();
    _invoiceNumber = invoiceNumber;
}





此后,在 RepF_Load 中我初始化了一些 DataTables 并用MySqlDataAdapters填充它们。





After this, in the RepF_Load I initialize some DataTables and fill them with MySqlDataAdapters.

      private void RepF_Load(object sender, EventArgs e)
        {
            this.reportViewer1.RefreshReport();

            StreamReader stR = File.OpenText(filePath);

            while (sLine != null)
            {
                sLine = stR.ReadLine();
                if (sLine != null)
                { fileEntries.Add(sLine); }
            }

            _hostName = fileEntries[0].ToString();
            _database = fileEntries[1].ToString();
            _portNumber = fileEntries[2].ToString();
            _userName = fileEntries[3].ToString();
            _userPassword = fileEntries[4].ToString();

            bdConn = new MySqlConnection("Server=" + _hostName + ";Port=" + _portNumber + ";Database=" + _database + ";Uid=" + _userName + ";Pwd=" + _userPassword + "; Connection Timeout = 3");
            string teste = "Server=" + _hostName + ";Port=" + _portNumber + ";Database=" + _database + ";Uid=" + _userName + ";Pwd=" + _userPassword;
            bdConn.Open();


            MySqlCommand mscInvoiceDetails = new MySqlCommand("SELECT invoice_code, dt_invoice, total_value, observation FROM tb_invoices WHERE invoice_code = \''" + _invoiceNumber + "\'';", bdConn);
            MySqlCommand mscInvoiceDescriptionDetails = new MySqlCommand("SELECT detail_description, detail_value, ind_taxible FROM tb_doc_details WHERE tb_invoices_id_invoice = (SELECT id_invoice FROM tb_invoices WHERE invoice_code = \''" + _invoiceNumber + "\'');", bdConn);
            MySqlCommand mscClientDetails = new MySqlCommand("SELECT company_name, company_registration, address, corporate_name FROM tb_client WHERE id = (SELECT tb_client_id FROM tb_invoices WHERE invoice_code = \''" + _invoiceNumber + "\'');", bdConn);
            MySqlCommand mscPaymentTypeDetails = new MySqlCommand("SELECT payment_type_name, payment_type_description FROM tb_payment_type WHERE id = (SELECT tb_payment_type_id FROM tb_invoices WHERE invoice_code = \''" + _invoiceNumber + "\'');", bdConn);
            MySqlCommand mscDocumentTypeDetails = new MySqlCommand("SELECT doc_type_cd FROM tb_doc_type WHERE id_doc_type = (SELECT tb_doc_type_id_doc_type FROM tb_invoices WHERE invoice_code = \''" + _invoiceNumber + "\'');", bdConn);


            MySqlDataAdapter mscDAdtInvoiceDetails = new MySqlDataAdapter(mscInvoiceDetails);
            mscDAdtInvoiceDetails.Fill(dtInvoiceDetails);

            MySqlDataAdapter mscDAdtInvoiceDescriptionDetails = new MySqlDataAdapter(mscInvoiceDescriptionDetails);
            mscDAdtInvoiceDescriptionDetails.Fill(dtInvoiceDescriptionDetails);

            MySqlDataAdapter mscDAdtClientDetails = new MySqlDataAdapter(mscClientDetails);
            mscDAdtClientDetails.Fill(dtClientDetails);

            MySqlDataAdapter mscDAdtPaymentTypeDetails = new MySqlDataAdapter(mscPaymentTypeDetails);
            mscDAdtPaymentTypeDetails.Fill(dtPaymentTypeDetails);

            MySqlDataAdapter mscDAdtDocumentTypeDetails = new MySqlDataAdapter(mscDocumentTypeDetails);
            mscDAdtDocumentTypeDetails.Fill(dtDocumentTypeDetails);
}

private void reportViewer1_Load(object sender, EventArgs e)
{

}







正如你所看到的,我没有 DataSet ,因为我正在创建和在代码执行期间填充我的 DataTables ,并且Microsoft Report Viewer组件在此Windows窗体( RepF )类中。



此Windows报告查看器已经配置了报告(带有文本框和表格)。



我需要知道的是:



如何使用存储在 DataTables 中的数据?在我的报告( Report1.rldc )中,查看并打印这些信息?





注意:



1 - 我使用的是Visual Studio Team System - C#

2 - 我不是经验丰富的程序员





提前致谢! :)




As you can see, I don''t have a DataSet, as I am creating and populating my DataTables during the code execution, and, the Microsoft Report Viewer component is in this Windows Form (RepF) class.

This Windows Report Viewer has its report already configured (with text boxes and a table).

What I need to know is:

How can I use the data stored in those DataTables in my report (Report1.rldc), to see and print those information?


Notes:

1 - I am using Visual Studio Team System - C#
2 - I am not an experienced programmer


Thanks in advance! :)

推荐答案

在您的解决方案中创建一个新的虚拟数据集&设计一个包含所需列的表(当然是空的)。现在在报表设计器中使用此表的字段(拖放即可)。



在您的代码中,填写一个与结构相同的DataTable。您的数据集。

将DataTable添加到报表数据源。

例如



ReportViewer1.LocalReport.DataSources .Add(_

新的Microsoft.Reporting.WinForms.ReportDataSource(ds1_tbl,dt))



其中ds1是您设计的数据集的名称和tbl是您设计的数据集中表格的名称

(不要忘记介于两者之间的下划线。)

并且

dt是您填写的DataTable

多数民众赞成。刷新报告&你应该得到它。
Create a new dummy dataset in your solution & design a table with the columns you want (empty of course). Now use the fields of this table in your report designer (drag & drop will do).

In your code, fill up a DataTable with the same structure as in your dataset.
Add the DataTable to the report data sources.
Eg

ReportViewer1.LocalReport.DataSources.Add( _
New Microsoft.Reporting.WinForms.ReportDataSource("ds1_tbl", dt))

where "ds1" is the name of the dataset you have designed and "tbl" is the name of the table in the dataset you designed
(don''t forget the underscore in between.)
and
dt is the DataTable that you have filled
Thats it. Refresh the report & you should get it.


确保这些东西

1)表格中的字段值(在报表设计器中)设置为

=字段!field1.Value,= Fields!field2.Value等

2)您创建了一个包含相同字段名称(field1,field2,field3)的DataTable并且它们具有相同的数据类型。

3)确保DataTable在使用DataSource添加它之前有一些行.Add()

4)在报表设计器中,选择表格,右击&选择属性。在常规选项卡中,选中数据集名称 - 它应为DataSet1_DataTable1。确保在添加数据源时使用相同的名称。 (区分大小写)

5)在报表查看器控件中,确保选择了report.rdlc文件。如果要将rdlc文件保留为外部资源,请告诉控件:ReportViewer1.LocalReport.ReportPath =C:\\ xxx.rdlc;



如果您仍然收到错误,请告诉我reportviewer控件显示的错误。
Make sure of these things
1) The values of the fields in the table (in report designer) are set like
=Fields!field1.Value , =Fields!field2.Value etc
2) That you have created a DataTable containing the same field names (field1,field2,field3) and they have the same data types.
3) Make sure that the DataTable has some rows before adding it using DataSources.Add()
4) In the report designer, select the table, right click & choose properties. In the General tab, check the ''Dataset Name'' - it should be "DataSet1_DataTable1". Make sure you are using the same name while adding datasources. (case sensitive)
5) In the report viewer control, make sure you have picked your report.rdlc file. If you are keeping the rdlc file as an external resource, tell the control that : ReportViewer1.LocalReport.ReportPath = "C:\\xxx.rdlc";

If you''re still getting an error let me know the error the reportviewer control is showing.


您所要做的就是删除那些设计器生成的绑定:)

我不知道你的问题。奇怪。

当我在一个数据集中维护2个表时,我遇到了一些有趣的问题。在尝试了很多东西之后,当我将每个表移动到一个唯一的数据集时,它工作正常。试试看 - 只需在设计器的一个DataSet中保留一个表

例如:

DataSet1_DataTable1,

DataSet2_DataTable2等

drag&从相关数据集&中删除字段为所有人添加报告数据源&刷新报告



它可能有效
All you had to do was to delete those designer generated bindings : )
I don''t know about your problem. weird.
I had some funny problems when i maintained 2 tables in one dataset. After trying lots of things, it worked correctly when i moved each table to a unique dataset. Try that - just keep only one table in one DataSet in the designer
Eg:
DataSet1_DataTable1,
DataSet2_DataTable2 etc.
drag & drop fields from the related Datasets & add Report DataSources for all of them & refresh report

It might work


这篇关于使用Microsoft Report Viewer中的DataTables中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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