2012-06-28 17 views
5

के XML डेटा स्रोत को बदलना मैंने क्रिस्टल रिपोर्ट बनाई और इसे C:\SomeDir\Data.xml पर एक XML फ़ाइल से कनेक्ट किया।क्रिस्टल रिपोर्ट

रनटाइम पर, मुझे डेटा को C:\SomeOtherDir\Data.xml में रखना पड़ सकता है।

कोड मेरे पास अब तक इस तरह दिखता है:

ReportDocument report = new ReportDocument(); 
report.Load("Report.rpt"); 
PrinterSettings printerSettings = new PrinterSettings(); 
PageSettings pageSettings = printerSettings.DefaultPageSettings; 
report.PrintToPrinter(printerSettings, pageSettings, false); 

कि C:\SomeDir\Data.xml पर डेटा के साथ रिपोर्ट प्रिंट होगा। मैं चाहता हूं कि यह डेटा C:\SomeOtherDir\Data.xml पर प्रिंट करें।

मैं यह कैसे कर सकता हूं?

+0

में आप एक्सएमएल से रिपोर्ट लोड करने के लिए कोड पोस्ट कर सकते हैं? – Urik

+0

@Urik: कोई कोड नहीं है। रिपोर्ट एक्सएमएल फाइल से जुड़ी है। –

+0

लेकिन क्या आप rpt.Database.Tables जैसे कुछ उपयोग नहीं कर रहे हैं [0] .SetDataSource (ds_xml); ? – Urik

उत्तर

0

जावा में यदि मैं रन टाइम पर डेटा का एक नया सेट प्रतिस्थापित करना चाहता हूं तो मैं आम तौर पर उस डेटा में लोड करूंगा (चाहे वह डीबी या एक्सएमएल या जो भी हो) परिणाम हो और इसे rpt.Database.Tables के माध्यम से दबाएं .setDataSource मूल डेटा के 'टेबल उपनाम' को पास कर रहा है, इसलिए सीआर जानता है कि ओवरराइट करना क्या है। यह संभवतः सी # में समान होगा। आप उस पर ब्रश करना चाहते हैं, इसे आज़माएं और फिर अधिक प्रश्नों के साथ वापस आएं।

1
ReportDocument report = new ReportDocument(); 
report.Load("Report.rpt"); 

DataSet reportData = new DataSet(); 
reportData.ReadXml(@"C:\SomeOtherDir\Data.xml"); 
report.SetDataSource(reportData); 

PrinterSettings printerSettings = new PrinterSettings(); 
PageSettings pageSettings = printerSettings.DefaultPageSettings; 
report.PrintToPrinter(printerSettings, pageSettings, false); 

एक्सएमएल परिवर्तन की स्कीमा, आप सीआर संपादक में रिपोर्ट को खोलने और "सत्यापित डेटाबेस" स्कीमा यह स्वाभाविक है अद्यतन करने के लिए, या यह रहस्यमय फेंक होगा की आवश्यकता होगी, तो "लॉग ऑन विफल" त्रुटि।

0
Imports CrystalDecisions.Shared 
Imports CrystalDecisions.CrystalReports.Engine 
Imports BL 

Public Class frmRptViewer 
    Dim strReportName As String 
    Dim ds As New DataSet 
    Public bl As New BL.InvoiceBL 
    Private Sub configureCrystalReports() 
     Dim strReportName As String 
     Try 
      strReportName = "Inv" 
      ds = bl.FillHDDT(TrnCode) 
      Dim strReportPath As String = Application.StartupPath & "\Reports\" & strReportName & ".rpt" 
      Dim rptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument 
      ds.WriteXml(Application.StartupPath & "\xmlFiles\INVOICE.xml", XmlWriteMode.WriteSchema) 
      rptDocument.Load(strReportPath) 

      Dim crpConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo 
      With crpConnectionInfo 
       .ServerName = Application.StartupPath & "\xmlFiles\INVOICE.xml" 
       .DatabaseName = "NewDataset" 
       .UserID = "" 
       .Password = "" 
      End With 

      Dim tblCurrent As Table 
      Dim crpTableLogOnInfo As New CrystalDecisions.Shared.TableLogOnInfo() 
      For Each tblCurrent In rptDocument.Database.Tables 
       tblCurrent.LogOnInfo.ConnectionInfo.ServerName = Application.StartupPath & "\xmlFiles\INVOICE.xml" 
       tblCurrent.LogOnInfo.ConnectionInfo.DatabaseName = "NewDataset" 
       tblCurrent.LogOnInfo.ConnectionInfo.UserID = "" 
       tblCurrent.LogOnInfo.ConnectionInfo.Password = "" 
       tblCurrent.LogOnInfo.ConnectionInfo.Type = CrystalDecisions.Shared.ConnectionInfoType.MetaData 
      Next 
      rptDocument.Database.Tables(0).SetDataSource(ds.Tables("Table")) 
      rptDocument.Database.Tables(1).SetDataSource(ds.Tables("Table1")) 

      crptViewer.ShowRefreshButton = False 
      crptViewer.ShowCloseButton = False 
      crptViewer.ShowGroupTreeButton = False 
      crptViewer.ReportSource = rptDocument 
     Catch ex As Exception 
     End Try 
    End Sub 
+0

यह काम करता है? – deltu100

0

आप शुरुआत से की जरूरत है, पर विचार की जरूरत प्रिंट DataGridView डेटा XML का उपयोग Crystelreport में दिखाने

**(This is very helpful if you not using any database)** 
  1. पहले मेकअप डेटा तालिका
  2. फिर जोड़ने डेटा तालिका में डेटा जोड़ें (यहाँ डेटाग्रिडव्यू से)
  3. एक्सएमएल फ़ाइल
  4. रन रिपोर्ट

यहाँ नमूना कोड

DataTable dt = new DataTable(); 
dt.Columns.Add("Item_Id", typeof(string)); 
dt.Columns.Add("Categry", typeof(string)); 
dt.Columns.Add("Item_Name", typeof(string)); 
dt.Columns.Add("Unit_Price", typeof(double)); 
dt.Columns.Add("Quantity", typeof(int)); 
dt.Columns.Add("Discount", typeof(string)); 
dt.Columns.Add("Total_Payable", typeof(double)); 
    foreach (DataGridViewRow dgr in DGVsell.Rows) 
{ 
    dt.Rows.Add(dgr.Cells[0].Value, dgr.Cells[1].Value, dgr.Cells[2].Value, dgr.Cells[3].Value, dgr.Cells[4].Value, dgr.Cells[5].Value, dgr.Cells[6].Value); 
} 
ds.Tables.Add(dt); 
ds.WriteXmlSchema("Bill.xml"); 

टिप्पणी का पालन के रूप में किया था त्रुटि Xml परिवर्तन App.config फ़ाइल बनाने हैं

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    </startup>--> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
</configuration> 

चिह्नित xml फ़ाइल के बाद, आप के लिए कॉल कर सकते हैं क्रिस्टल रिपोर्ट

frmreport obj = new frmreport(); //load report viwer form 
obj.ShowDialog(); 

रिपोर्ट viwer

crBill cr = new crBill(); 
cr.SetDataSource(frmSell.ds); 
crystalReportViewer1.ReportSource = cr; 
crystalReportViewer1.RefreshReport(); 
crystalReportViewer1.Refresh(); 
संबंधित मुद्दे