推荐vb6中如何调用水晶报表9做的报表
引用ado及crystal report9 activex designer design time library(internal)
使用控件 crystal report viewer contral
priver sub form_load()
dim strsql as string
Dim i As Integer
dim capp As New CRAXDRT.Application
dim carp As New CRAXDRT.Report
dim cn as new adodb.connection
dim rs as new adodb.recordset
If cn.State = adStateOpen Then cn.Close
With cn
.Provider = "sqloledb"
.ConnectionString = "data source=dd;initial catalog=dfd;user id=sa;password=aaa"
.Open
End With
strsql="select * from tabname"
If rs.State = adStateOpen Then rs.Close
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open strsql, cn, adOpenDynamic, adLockOptimistic
End With
Set carp = capp.OpenReport("E:/reports/finisher.rpt")
For i = 1 To carp.Database.Tables.Count
If carp.Database.Tables.Item(i).Name = "ado" Then
carp.Database.Tables(i).SetDataSource rs
End If
Next
crviw.ReportSource = carp
crviw.ViewReport
crviw.Zoom 100
end sub
---------------------------------------------------------------
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