我创建了一个可以正常运行的Crystal Report,但它需要输入登录信息。我用Google搜索并找到此代码,但它对我不起作用。任何带代码的建议都将受到高度赞赏。
private void frmPrintWIPReport_Load(object sender, EventArgs e)
{
var cryRpt = new ReportDocument();
var crtableLogoninfo = new TableLogOnInfo();
var crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("rptWIP.rpt");
crConnectionInfo.ServerName = "192.168.40.253";
crConnectionInfo.DatabaseName = "TNET";
crConnectionInfo.IntegratedSecurity = true;
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "******";
CrTables = cryRpt.Database.Tables;
foreach (Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
答案 0 :(得分:0)
你可以试试这个。我希望它和你的需要一样。
private void frmPrintWIPReport_Load(object sender, EventArgs e)
{
var cryRpt = new ReportDocument();
var crtableLogoninfo = new TableLogOnInfo();
var crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("rptWIP.rpt");
ConnectionInfo crConnectionInfo = new ConnectionInfo()
{
ServerName = @"192.168.40.253",
DatabaseName = @"TNET",
UserID=@"sa",
Password=@"******"
//IntegratedSecurity = true
};
CrTables = cryRpt.Database.Tables;
foreach (Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}