vb 调用水晶报表,要传递给水晶报表 连接sql的信息 还有参数字段值,改如何做!
我写了个代码如下:
Option Explicit
Private objCRApp As New CRAXDRT.Application '水晶报表应用程序对象
Private objCRReport As New CRAXDRT.Report '报表对象
Private Sub Form_Load()
Dim props As CRAXDRT.ConnectionProperties '报表数据源参数集
Dim prop As CRAXDRT.ConnectionProperty '报表数据源参数
Dim adoCon As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CnnStr As String
Dim strSQL As String
rst.CursorLocation = adUseClient
CnnStr = ""
CnnStr = "provider=SQLOLEDB;Data Source=192.168.0.11;Database=Demo_app ;UID=dm1;PWD=dm1;"
strSQL = "SELECT top 5 description FROM item_all "
adoCon.Open CnnStr
rst.Open strSQL, adoCon, adOpenStatic, adLockReadOnly
Dim strTotal As String
strTotal = ""
adoCon.CursorLocation = adUseClient
Set objCRReport = objCRApp.OpenReport(App.Path & "\report.rpt", 1)
Set props = Nothing
' 清除报表中保持的数据
'让模板中设置的参数不出现提示框!!!!
objCRReport.EnableParameterPrompting = True '不进行报表参数提示
objCRReport.DiscardSavedData
' 赋给报表数据
objCRReport.Database.SetDataSource rst, 3, 1
'指定报表来源
CRViewer91.ReportSource = objCRReport
'显示报表
CRViewer91.ViewReport
Set rst = Nothing
运行后水晶报表提示 该字段未知!
帮看看什么问题啊!
------解决方案--------------------
changechange
大侠是Access专家,是其他数据库开发大版技术专家分NO.1。
抱歉这里 水晶报表 方面的高手不多,看看帖子回复数就知道了。
------解决方案--------------------
你的代码上并没有什么问题,但可能代码和报表模板不匹配
SELECT top 5 description FROM item_all
注意看一下你的模板里设计的时候,表名和字段是不是跟上面的一样
而且,你的报表里是否有公式等里面用到了字段,但是字段输入错误
或者
你后来更改了数据表结构,但没有同步更新报表模板?
------解决方案--------------------
。。
我所有的文章都没用过这句:
rpt.Database.LogOnServer "p2ssql.dll", "Demo_app", "192.168.0.11", "sa", "gming751112"
呵呵~~
而且你如果用了ttx模式的话,那么
Dim tbl As CRAXDDRT.DatabaseTable
Dim tbls As CRAXDDRT.DatabaseTables
这两句是不要用的
这两篇你看过吗?
http://www.cnblogs.com/babyt/archive/2005/03/11/116878.html
http://www.cnblogs.com/babyt/archive/2005/03/11/116880.html
看会了这个,用VB开发水晶报表基本上可以全部做下来的。