在运行时设置 Crystal Report 数据源 [英] Setting Crystal Report data source at runtime

查看:21
本文介绍了在运行时设置 Crystal Report 数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建 Crystal Report 时,我显然设置了用于开发的数据库和服务器连接.

When creating my Crystal Report I obviously set up a database and server connection that I use for development.

我现在想要在我的 VB 应用程序中做的是动态设置数据库和服务器名称以用于报告.我将这些值作为字符串 varServer 和 varDatabase.

What I want to do now in my VB application is to dynamically set the database and server name to use with the reports. I have these values as the strings varServer and varDatabase.

有人知道怎么做吗?

提前致谢.

P.S 我尝试了几种在线解决方案,但在使用 VB6 时遇到了问题.

P.S I have tried several online solutions but am having trouble with VB6.

推荐答案

这个链接有你想知道的所有信息.

This link has all information you want to know.

更新:这是与 SQL Server 集成身份验证的最低工作示例.您应该使用表对象的 ConnectionProperties 来设置连接参数.

UPDATE: Here is a minimum working sample for integrated authentication with SQL Server. You should use the ConnectionProperties of the table object to set connection parameters.

Dim app As New CRAXDDRT.Application
Dim rpt As CRAXDDRT.Report
Dim tbl As CRAXDDRT.DatabaseTable
Dim tbls As CRAXDDRT.DatabaseTables

Set rpt = app.OpenReport("C:
eport
epotest.rpt")

For Each tbl In rpt.Database.Tables
    tbl.ConnectionProperties.DeleteAll
    tbl.ConnectionProperties.Add "Provider", "SQLOLEDB"
    tbl.ConnectionProperties.Add "Data Source", "localhost"
    tbl.ConnectionProperties.Add "Initial Catalog", "testdb"
    tbl.ConnectionProperties.Add "Integrated Security", "True"   ' cut for sql authentication
    'tbl.ConnectionProperties.Add "User Id", "myuser"   ' add for sql authentication
    'tbl.ConnectionProperties.Add "Password", "mypass"  ' add for sql authentication
Next tbl

'This removes the schema from the Database Table's Location property.
Set tbls = rpt.Database.Tables
For Each tbl In tbls
    With tbl
        .Location = .Name
    End With
Next

'View the report
Viewer.ReportSource = rpt
Viewer.ViewReport

这篇关于在运行时设置 Crystal Report 数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆