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

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

问题描述

在创建我的Crystal报表时,我显然设置了一个用于开发的数据库和服务器连接。

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.

任何人都知道如何去做这个?

Anyone know how to go about doing this?

提前感谢。

我尝试过几个在线解决方案,但是遇到了VB6的问题。

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

推荐答案

此链接包含所有信息

UPDATE:以下是使用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:\report\repotest.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天全站免登陆