在VB中使用了水井报表。并创建了connection 和 recordset对象。并查询了纪录。请问该如何让这些数据提供到水井报表里面去。

解决方案 »

  1.   

    Dim  ReportDoc  As  New  ReportDocument()  
    Dim  logonInfo  As  New  TableLogonInfo  
    Dim  table  As  table  
    ReportDoc.Load("C:\Rpts\publish.rpt")  
    For  Each  table  IN  ReportDoc.DataBase.Tables  
                   logonInfo=  table.LogonInfo  
                   with  logonInfo.connectioninfo  
                       .serverName=  "Localhost"  
                       .Databasename=  "pubs"  
                       .UserID=  "sa"  
                       .Password=""  
                   End  With  
                   table.applyLogonInfo(logonInfo)  
    next  table  
    Crviewer.reportsource=  reportDoc  
      

  2.   

    Dim  CryApp  As  New  CRAXDDRT.Application  
           Dim  Report  As  CRAXDDRT.Report  
             
           Dim  strCnn  As  String  
           Set  Report  =  CryApp.OpenReport(App.Path  &  "\report2.rpt")  
     
           Dim  cnn1  As  New  ADODB.Connection  
           Dim  adoRS  As  New  ADODB.Recordset  
             
           strCnn  =  "Provider=sqloledb;Data  Source=abrams;Initial  Catalog=salestesttmp;User  Id=sa;Password=test;"  
           cnn1.Open  strCnn  
             
           adoRS.Open  "select  top  10  *  from  answers",  cnn1,  adOpenDynamic,  adLockBatchOptimistic  
           Report.Database.SetDataSource  adoRS  
     
           Screen.MousePointer  =  vbHourglass  
           CRViewer91.ReportSource  =  Report  
           CRViewer91.ViewReport  
           Screen.MousePointer  =  vbDefault
      

  3.   

    在  Crystal  Reports  9  安装目录下有例子
      

  4.   

    Screen.MousePointer = vbHourglass
    '''显示方式一:情况为报表直接在工程设计器中制作(Dsr文件)
    '---------------------
    ''CRViewer91.ReportSource = Report
    ''CRViewer91.ViewReport
    '----------------------
    '显示方式二:情况为报表在水晶报表软件中制作(rpt文件)
    Dim capp As New CRAXDDRT.Application
    Dim carp As New CRAXDRT.Report
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strsql As String
    Dim i As Integer
    If cn.State = adStateOpen Then cn.Close
    '''''SQL SERVER连接方式
    '''With cn
    '''.Provider = "sqloledb"
    '''.ConnectionString = "data source=dd;initial catalog=dfd;user id=sa;password=aaa"
    '''.Open
    '''End With
    'Mdb的连接方式
    With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    '.ConnectionString = "Data Source='" + App.Path + "\temp.mdb;Jet OLEDB:Engine Type=5;Locale Identifier=0x0804;Jet OLEDB:Database Password="
    .ConnectionString = "Data Source=" + App.Path + "\Test.mdb;Persist Security Info=False"
    .Open
    End Withstrsql = "select * from carsort"
    If rs.State = adStateOpen Then rs.Close
    With rs
    .ActiveConnection = cn
    .CursorLocation = adUseClient
    .Open strsql, cn, adOpenDynamic, adLockOptimistic
    End WithSet carp = capp.OpenReport(App.Path + "\CryStalTest.rpt")
    For i = 1 To carp.Database.Tables.Count
    If carp.Database.Tables.Item(i).Name = "carsort" Then
    carp.Database.Tables(i).SetDataSource rs
    End If
    Next
    Screen.MousePointer = vbHourglass
    '第一种方式
    ''carp.ParameterFields(1).ClearCurrentValueAndRange
    ''carp.ParameterFields(1).AddCurrentValue ("myhgyp")
    ''carp.ParameterFields(2).ClearCurrentValueAndRange
    ''carp.ParameterFields(2).AddCurrentValue (CInt("3"))
    carp.ParameterFields.GetItemByName("gg").ClearCurrentValueAndRange
    carp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myh111111111111111111111111111111111111" & Chr(13) & Chr(10) & "-22222222222222222222222222222222222222222222222222222222222gyp")
    'carp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myhgyp")
    carp.ParameterFields.GetItemByName("ff").ClearCurrentValueAndRange
    carp.ParameterFields.GetItemByName("ff").AddCurrentValue (CInt("673"))
    CRViewer91.ReportSource = carpCRViewer91.ViewReport
    Screen.MousePointer = vbDefault
    CRViewer91.Zoom 100
    '----------------------
    Screen.MousePointer = vbDefault