關於水晶報表提示輸入賬號、密碼的問題

bruce168 2009-04-14 11:53:49
我現在用VS2008裡面自帶的Crystal Report功能開發了一些報表;在開發時間連的是開發環境Server、DataBase、UserID、Password;可是上到正式環境之後,它卻不能按照我程式裡面指定的連接到正式環境;相關代碼如下:
在【預覽報表】後臺按鈕觸發:
For i As Integer = 0 To obj.LogOnInfo.Count - 1
myConnectionInfo = New ConnectionInfo()
With myConnectionInfo
.ServerName = "GZServer"
.DatabaseName = "HRS"
.UserID = "HRS"
.Password = "1234"
End With
obj.LogOnInfo(i).ConnectionInfo = myConnectionInfo
Next
...全文
125 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jietuan 2009-04-14
  • 打赏
  • 举报
回复
同意上面的,请使用后期绑定;不要在设计阶段设置数据库连接。
阿泰 2009-04-14
  • 打赏
  • 举报
回复
报表登录信息应该是这样的,你参考下下列代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace CS_Base
{
public partial class Form1 : Form
{
private ReportDocument northwindCustomersReport;

public Form1()
{
InitializeComponent();
}

private void ConfigureCrystalReports()
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.DatabaseName = "Northwind";
connectionInfo.UserID = "limitedPermissionAccount";
connectionInfo.Password = "1234";
connectionInfo.ServerName = "dholmes_50701";

northwindCustomersReport = new ReportDocument();
string reportPath = Application.StartupPath + "\\" + "NorthwindCustomers.rpt";
northwindCustomersReport.Load(reportPath);
crystalReportViewer.ReportSource = northwindCustomersReport;

SetDBLogonForReport(connectionInfo, northwindCustomersReport);

}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);

}
}


private void Form1_Load(object sender, EventArgs e)
{
ConfigureCrystalReports();
}

private void crystalReportViewer_Load(object sender, EventArgs e)
{

}
}
}
bruce168 2009-04-14
  • 打赏
  • 举报
回复
可是我的報表的過濾條件很多,所以我想在點擊【預覽】按鈕的時候才產生報表;而不是在Page_Load的時候;那該怎么做呢?而且我現在直接用的是Crystal Report,而沒有調用中間變量Report Document;而且我還有很多參數輸入!

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧