VB.NET:客户端Windows报表帮助 [英] VB.NET : Help with client-side Windows Reporting

查看:65
本文介绍了VB.NET:客户端Windows报表帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好聪明的人

我有一个问题,我已经尝试了好几天了,以使我的报告顺利进行.我在网上搜索了一下,却没有发现有用的信息.

我的报告想显示一家公司的《销售日记》.在数据源中,我设置了带有两个数据表的数据集(myDataSet).数据是:
1.主表:-myCompanyTable
-公司
-FromDate
-ToDate

2.子表:-myDataTable
-InvNr
-DDate
-说明
-AccountNr
-货币
-金额
-FXRate
-ConvAmount
-公司

我还创建了两个报告,一个是主报告(rptSalesJournalHeader.rdlc),另一个是子报告(rptCustInvoiceList.rdlc)

-rptSalesJournalHeader.rdlc有一个列表项,在该列表项中,"myCompanyTable"和子报表中有3个文本框,这些文本框链接到"rptCustInvoiceList.rdlc". listitem的数据集名称="myDataSet_myCompanyTable".

-rptCustInvoiceList.rdlc具有保存myDataTable列的表.过滤器部分中的表属性具有以下内容:
= Fields!Company.Value = = Parameters!parCompanyName.Value.

现在,位于frmReports中的代码为folloes:

Hi wonderful smart people

I have a problem, I have been trying for days to get my report working with no luck. I googled the web and found nothing that useful.

My report suppose to show the Sales Journal for a company. In the datasourses I have set a dataset (myDataSet) with its two datatables. The datables are :
1. Main table :- myCompanyTable
- Company
- FromDate
- ToDate

2. SubTable :- myDataTable
-InvNr
-DDate
-Description
-AccountNr
-Currency
-Amount
-FXRate
-ConvAmount
-Company

I also created two reports, one the main report (rptSalesJournalHeader.rdlc) and the subreport (rptCustInvoiceList.rdlc)

-The rptSalesJournalHeader.rdlc has a listitem, in the listitem there are 3 textboxes from the "myCompanyTable" and subreport which is linked to "rptCustInvoiceList.rdlc". The listitem''s dataset name="myDataSet_myCompanyTable".

- The rptCustInvoiceList.rdlc has the table that hold myDataTable columns. The table properties in the filters section has the following:
=Fields!Company.Value = =Parameters!parCompanyName.Value.

Now the code which is sitting in the frmReports is as folloes:

Imports MySql.Data.MySqlClient
Imports System.Data.ODBC
Imports System.Data
Imports System.Data.DataSet
Imports System.Collections
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.Reporting.WinForms
Public Class frmReports
    Public Sub New()
        InitializeComponent()
    End Sub
    Dim dsReport As DataSet = New myDataSet
    '' Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)
    Private Sub frmReports_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        conn.ConnectionString = connectToDB("command")
        Dim cmdReport As MySqlCommand = New MySqlCommand()
        Dim drReport As MySqlDataReader
        Try
            '' open connection
            conn.Open()
            cmdReport.CommandType = CommandType.Text
            cmdReport.Connection = conn
            Dim SQL As String
            SQL = "  SELECT Value as Company,(if(Value<>'''',''" & startDate & "'',''01/01/2009'')) As FromDate,(if(Value<>'''',''" & endDate & "'',''01/01/2009'')) As ToDate FROM setting WHERE setting.ID=''CompanyName'';"
            SQL = SQL & "   SELECT Reference as InvNr,TransactionDate as DDate,Description,Sub_LEDGER as AccountNr,BillCurr as Currency,Amount, FXRate,(Amount*FXRate) as ConvAmount,(SELECT Value AS Company FROM setting WHERE setting.ID=''CompanyName'') AS Company FROM tbltransactions "
            SQL = SQL & "  WHERE billcurr=''KES'' AND  Account = ''G-10001''  "
            SQL = SQL & "  AND TransactionDate > ''2009-01-01'' AND TransactionDate < ''2009-12-31''  "
            SQL = SQL & "  AND TransType = ''Debtors Journal'' "
            SQL = SQL & "  UNION SELECT InvoiceNo as InvNr,Date,tblClients.Client as Description,ClientID as AccountNr,tblCustomerinvoices.Currency,Amount,   If(Amount<>0,1,0) as FXRate,(Amount*1) as ConvAmount,(SELECT Value AS Company FROM setting WHERE setting.ID=''CompanyName'') AS Company "
            SQL = SQL & "   FROM(tblCustomerinvoices, tblClients)"
            SQL = SQL & "  WHERE tblcustomerinvoices.currency=''KES''  "
            SQL = SQL & "  AND Date > ''2009-01-01'' AND Date < ''2009-12-31'' AND invoice_status = ''unposted'' "
            SQL = SQL & "   AND tblClients.ID=tblcustomerinvoices.ClientID"
            cmdReport.CommandText = SQL
            '' execute query and load result to dataset
            drReport = cmdReport.ExecuteReader()
            dsReport.Load(drReport, LoadOption.OverwriteChanges, dsReport.Tables(1), dsReport.Tables(0))
            '' close connection
            drReport.Close()
            conn.Close()
            '' prepare report for view
            ReportViewer1.LocalReport.ReportEmbeddedResource = "Accounting.Net.rptSalesJournalHeader.rdlc"
            '' Add a handler for SubreportProcessing
            AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler
            Dim rds As ReportDataSource = New ReportDataSource()
            rds.Name = "myDataSet_myCompanyTable"
            rds.Value = dsReport.Tables(1)
            ReportViewer1.LocalReport.DataSources.Add(rds)
            '' preview the report
            ReportViewer1.RefreshReport()
        Catch ex As Exception

        End Try

    End Sub
    Private Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
        e.DataSources.Add(New ReportDataSource("myDataSet_myDatatable", dsReport.Tables(0)))
    End Sub
End Class



现在,当我运行此代码时,它给了我一个空白屏幕,为什么?我已经为此奋斗了好几天.您的帮助将使我成为地球上最幸福的人.我很绝望.

问候
Lindelani



Now when I run this code, it gives me a blank screen, why? I have struggled with this for days. Your help will make me the happiest person on planet earth. I am desparate.

Regards
Lindelani

推荐答案

要检查的几件事.
A couple of things to check.

  1. 您的sql语句是否返回任何数据?
  2. 您在报表中定义了一个参数(= Parameters!parCompanyName.Value),但没有为其提供报价.

  1. Is any data being returned from your sql statements?
  2. You have a parameter defined in the report (=Parameters!parCompanyName.Value) but you are not supplying a vlaue for it
Dim reportParamList As ReportParameter() = New ReportParameter(0) {}
Dim reportParam As New ReportParameter("parCompanyName", companyNameValue)
reportParamList(0) = reportParam
ReportViewer1.LocalReport.SetParameters(reportParamList)


这篇关于VB.NET:客户端Windows报表帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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