2011-04-20 62 views
0

您好即时通讯使用3层架构..如何将SQL查询传递给Crystal Report?

Public Function SelectVoucher() As DataSet 

    Try 
     Squery = "select a.VoucherNo,convert(char(10),a.VoucherDate,120) as VoucherDate, 
        a.TotDebit,b.CustomerName as PartyName,c.Particulars 
        from spendmoney a,mcustomermaster b,spendmoneychild c 
        where a.partycode=b.customercode and a.voucherno=c.voucherno and 
        a.voucherno=3" 
     Return objdal.DBread(Squery) 
    Catch ex As Exception 
     Throw ex 
    End Try 
End Function 

这是我已被使用的查询,但晶体报告不显示此查询..

它显示的所有字段..

但原始查询答案是这样的:

3  2011-08-28  1500   prakash   www 

这是我已经使用的编码。

sub crystalreport 

Dim ds As New DataSet 
Dim objrpt As New CrystalReport10 
ds = bol.SelectVoucher() 


If ds.Tables(0).Rows.Count > 0 Then 
objrpt.SetDataSource(bol.SelectVoucher()) 
CrystalReportViewer1.ReportSource = objrpt 
objrpt.Refresh() 
CrystalReportViewer1.RefreshReport() 
End If 

end sub 

如何将查询传递给Crystal Reports?

回答

0

从 'NET-CS2003_RAS-Unmanaged_CR115_Modify_Command-Table-SQL.zip' 样品中提取的张贴在Crystal Reports for .NET SDK Samples

// Crystal Reports declarations 
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument; 
CrystalDecisions.ReportAppServer.Controllers.DataDefController boDataDefController; 
CrystalDecisions.ReportAppServer.DataDefModel.Database boDatabase; 
CrystalDecisions.ReportAppServer.DataDefModel.CommandTable boCommandTable; 

// Load the report using the CR .NET SDK and get a handle on the ReportClientDocument 
boReportDocument.Load(Server.MapPath("Command table report.rpt")); 
boReportClientDocument = boReportDocument.ReportClientDocument; 

// Use the DataDefController to access the database and the command table. 
// Then display the current command table SQL in the textbox. 
boDataDefController = boReportClientDocument.DataDefController; 
boDatabase = boDataDefController.Database; 
boCommandTable = (CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)boDatabase.Tables[0]; 
boCommandTable.CommandText = sQuery; 

// Clean up 
boReportDocument.Close(); 
boReportDocument.Dispose(); 
相关问题