我正在开发vb6中的winform应用程序。我正在使用水晶报告4.6。我创建了一个水晶报告,显示表格中的所有数据(MS Access)。我取消选中保存数据和报告,我保存了报告。我只是想在应用程序中调用它。所以我在我的应用程序中包含了CrystalReportControl组件。现在我想设置要在报告中显示的记录。根据文本框的用户输入选择记录。 从以下代码中完成从数据库中恢复的记录。
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Set conn = New ADODB.Connection
conn.Open "provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path &"\faculty.mdb"
Set rs = New ADODB.Recordset
rs.Open "select * from facultydetails where eid=1234", conn, adOpenDynamic, adLockPessimistic
CrystalReport1.ReportFileName = App.Path & "\faculty.rpt"
Set CrystalReport1.DataSource = rs
CrystalReport1.Action = 1
End Sub
给该行一个错误:设置CrystalReport1.DataSource = rs: 由于财产是只写的。 告诉我报告的记录是如何动态的? Plz帮助我......
答案 0 :(得分:0)
而不是
Set CrystalReport1.DataSource = rs
做
CrystalReport1.DataSource = rs
编辑:
请查看以下示例,看看它是否对您有所帮助:
'CrystalReport1 is the name of the dsr file
Dim Report As New CrystalReport1
Dim cdoRowset As CrystalDataObject.CrystalComObject
Dim varArray() As Variant
'Open ADO Connection
Set m_cnAdo = New ADODB.Connection
m_cnAdo.ConnectionString = "DRIVER={SQL Server};UID=[UserID];PWD=[Password]" _
& ";SERVER=[Server];DATABASE=[Database]"
m_cnAdo.Open
Dim rsAdo As ADODB.Recordset
Dim cmdAdo As ADODB.Command
'Using Embedded Query
Set cmdAdo = New ADODB.Command
Set rsAdo = New ADODB.Recordset
cmdAdo.ActiveConnection = m_cnAdo
cmdAdo.CommandText = "SELECT * FROM Table WHERE Param = " & lngParam1
cmdAdo.CommandType = adCmdText
Set rsAdo = cmdAdo.Execute
Report.Database.SetDataSource rsAdo, 3, 1