给你拷贝一下,你可以参考一下:
---------------------------------------
回复人: acptvb(微软全球技术中心 VB技术支持) (  ) 信誉:86  2002-3-7 15:04:33  得分:20  
 
 
  感谢您使用微软产品。在VB.NET中,使用Crystal Report制作报表时,碰到出现Database Login数据库登录窗口,是由于报表访问的后台数据库MS SQL Server需要提供登录信息。
如果您是通过OLE DB(ADO)的方式来访问后台数据库,则报表文件自身去提取数据,不需要编写代码。但如果后台数据库需要认证(如MS SQL Server),则应提供登录信息。如下提供一段示例代码供您参考:
(Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared)
        Dim crReport As New CrystalReport1()
        Dim repDB As Database = crReport.Database
        Dim repTbls As Tables = repDB.Tables
        Dim repTbl As Table        repTbl = repTbls(0)
        Dim logonInfo As TableLogOnInfo = repTbl.LogOnInfo
        logonInfo.ConnectionInfo.Password = "password"
        repTbl.ApplyLogOnInfo(logonInfo)
        CrystalReportViewer1.ReportSource = crReport如果您是通过DataSet的方式来访问后台数据库,则需要您手动编码来提取数据,填充DataSet,并传递到报表文件中,当然需提供数据库登录信息,建立连接。如下提供一段示例代码供您参考:
    Private Sub BindReport()
        Dim myConnection As New SqlClient.SqlConnection()
        myConnection.ConnectionString = "Server=localhost;database=pubs;Trusted_Connection=yes"        Dim myCommand As New SqlClient.SqlCommand()
        myCommand.Connection = myConnection
        myCommand.CommandText = "Select * from Stores"
        myCommand.CommandType = CommandType.Text        Dim myDA As New SqlClient.SqlDataAdapter()
        myDA.SelectCommand = myCommand        Dim myDS As New Dataset1()
        myDA.Fill(myDS, "Stores")
        Dim oRpt As New CrystalReport1()
        oRpt.SetDataSource(myDS)
        CrystalReportViewer1.ReportSource = oRpt
    End Sub
请根据您系统的实际情况,将提供的代码进行修改。希望以上答复给您带来帮助。
关于Crystal Report的更详细信息,请参考如下网站:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q100368
http://community.crystaldecisions.net/
 — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。  -------------------------------------------感谢您使用微软产品。您可以通过两种方法来实现Crystal Report报表的打印:
1,通过CrystalReportViewr控件提供的打印按钮,就可实现报表的打印;
此时,不需要编写打印操作的代码。但是,需要设置CrystalReportViewer控件的ReportSource属性,指出报表文件;
2,另一种方法是,自己编写代码,直接执行打印操作;
此时,可以采用ReportDocument对象的PrintToPrinter()这个方法。该方法的原型如下:
Public Overridable Sub PrintToPrinter(ByVal nCopies As Integer, ByVal collated As Boolean, ByVal startPageN As Integer, ByVal endPageN As Integer)
其中参数说明:
nCopies 打印份数;
collated 是否逐份打印;
startPageN 开始打印页;
endPageN 最后打印页;
如果打印所有页,则设置startPageN = 0和endPageN = 0
下面提供一段示例代码,供您参考:
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
……
Private Sub PrintReport(ByVal printerName As String)
   Dim Report As New ReportDocument()
   ' Load the report.
   Report.Load(reportName)   Dim margins As PageMargins   ' Get the PageMargins structure and set the 
   ' margins for the report.
   margins = Report.PrintOptions.PageMargins
   margins.bottomMargin = 350
   margins.leftMargin = 350
   margins.rightMargin = 350
   margins.topMargin = 350
   ' Apply the page margins.
   Report.PrintOptions.ApplyPageMargins(margins)   ' Select the printer.
   Report.PrintOptions.PrinterName = printerName   ' Print the report. Set the startPageN and endPageN
   ' parameters to 0 to print all pages.
   Report.PrintToPrinter(1, False, 0, 0)
End Sub关于PrintToPrinter方法的更详细信息,请参考如下网站:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfreportdocumentclassprinttoprintermethodtopic.asp关于Crystal Report的更详细信息,请参考如下网站:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q100368
http://community.crystaldecisions.net/
 — 微软全球技术中心 VB支持中心

解决方案 »

  1.   

    這個問題簡單得很
    在你生成報表(rpt)文檔時不是有一輸入服務器名,用戶,密碼,數據庫嗎
    在下面有一個打選項,選 中就行了。
      

  2.   

    设计报表时把数据源绑定XSD文件比较方便.
      

  3.   

    這個問題簡單得很
    在你生成報表(rpt)文檔時不是有一輸入服務器名,用戶,密碼,數據庫嗎
    在下面有一個打選項,選 中就行了。你指的是??集成安全这个选项么?
    那不行~那是利用WINDOWS登陆的帐号和密码的~
    和数据库用户不一样的!