如何获取负载报告文档的动态路径? [英] How to get dynamic path for load Report Document?

查看:66
本文介绍了如何获取负载报告文档的动态路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的荣誉,

我正在开发一个Windows应用程序.在那个项目中,我有一些水晶报告.

当我单击打印"按钮时,报告应自动打印.

以下代码在我的本地系统中运行良好.如果我在另一个系统中的项目中运行它,则会出错.

因此,我需要您的建议,如何获取负载报告文档的动态路径?.

这是我的代码:

Dear honors,

I''m developing one windows application. In that project I''ve some crystal reports.

When I click the print button the report should print automatically.

The following code works fine in my local system. If I run my in project another system it gets error.

So I need your suggestion, how to get the dynamic path for load Report Document?.

Here my code:

public void PrintMethod()
      {
          lsInvNo = frmCustomerInv.gsInvNo;
          string query2 = "select InvNo from tblCustomerInvoice where InvNo='" + lsInvNo + "' and State=''";
          string InvoNu = DataAccess.GetSingleValue(query2);
          if (InvoNu == "")
          {
              lsInvNo = "";
              MessageBox.Show("This Invoice Number Not in Customer Invoice List!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
              Query = "select distinct p.InvNo,p.InvDate ,p.CustomerName,p.TinNo,p.Sno,p.vehicleNo,p.ProductName,p.ProductKg,p.Packing,p.Units,p.Rate,p.Amount,p.Address,a.Mobile,a.CSTNO,c.NetAmt,c.Tax,c.TotAmt,w.Words  from tblCustomerInvoice as p inner join tblCustomerDetails as a on p.CustomerName=a.CustomerName inner join tblcustomerInvoiceAmt as c on c.InvNo=p.InvNo inner join tblCustomerInvWords as w on p.InvNo=w.InvNo where p.InvNo='" + lsInvNo + "'order by Sno";

          }
          else
          {
              SqlCon = dbCon.DBOpenConnection();
              Query = "select distinct p.InvNo,p.InvDate ,p.CustomerName,p.TinNo,p.Sno,p.vehicleNo,p.ProductName,p.ProductKg,p.Packing,p.Units,p.Rate,p.Amount,p.Address,a.Mobile,a.CSTNO,c.NetAmt,c.Tax,c.TotAmt,w.Words  from tblCustomerInvoice as p inner join tblCustomerDetails as a on p.CustomerName=a.CustomerName inner join tblcustomerInvoiceAmt as c on c.InvNo=p.InvNo inner join tblCustomerInvWords as w on p.InvNo=w.InvNo where p.InvNo='" + lsInvNo + "'order by Sno";
          }
          SqlDa = new SqlDataAdapter(Query, SqlCon);
          DataTable dt = new DataTable();
          dt.Clear();
          SqlDa.Fill(dt);
          ReportDocument REportDoct = new ReportDocument();
          REportDoct.Load(@"D:\vsp\vsp\Project\Reports\FinalInvoice.rpt");
          REportDoct.SetDataSource(dt);
          crystalReportViewer1.ReportSource = REportDoct;
          crystalReportViewer1.Refresh();
          REportDoct.PrintToPrinter(1, false, 0, 0);

      }




在此先感谢..




Thanks in Advance..

推荐答案

我认为这不是因为Report Path,这是DataBase的情况.当我们在其他系统上运行项目时,它会询问Path.我在开发我的第一个项目"时也遇到了相同的错误.发生这种情况
由于数据库更改的路径,当您在其他系统上运行项目时.
解决方案是必须创建DataSet,该数据集将创建永久的数据库结构,无论您在系统上运行项目还是在其他任何项目上运行,该结构都是固定的.

我使用以下代码解决了这个问题.
I think this is Not because of Report Path, this is becase of DataBase.When we Run project on other System it Ask Path.I was also got the same error when i was developing My First Project.This happens
because of Path of DataBase Change When you run yor project on other System.
The solution on that is you have to Create DataSet Which create permanent Structure of DataBase which is fixed whether you run your project on your System or Anywere else.

I used the following code which solve this problem.
Public Class FormReport
 'Creating New Objects
 Dim DataSet As New Data.DataSet
 Dim DataView As New Data.DataView
 Dim report As New ReportName 'ReportName is the Name of the Report Display in SolutionExplorer
 Dim objda As New OledbDataAdapter

Private Sub FormReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenConnection()'To Open DataBase Connection
        DataSet.Clear()
        objda.SelectCommand.CommandText = "SELECT * FROM TabelName"
        Try
            objda.SelectCommand.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)'Display Error if Any
        End Try
        objda.Fill(DataSet, "TabelName")
        DataView.Table = DataSet.Tables("TabelName")
        report.SetDataSource(DataView)
        'Clearing ReportViewer Source
        CrystalReportViewer1.ReportSource = ""
        'Set Report to ReportViewer
        CrystalReportViewer1.ReportSource = report
End Sub
End Class


已经回答了类似的问题在此之前,请检查一下.
[已解决]如何包含RPT文件具有Crystal Reports的C#应用​​程序中的路径 [
Already answered a similar question here before, check it.
[Solved] How to include RPT file path in C# apps with crystal report[^]


这篇关于如何获取负载报告文档的动态路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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