以编程方式验证晶体报告数据集是否已更改。 [英] Programmatically validate if crystal report dataset is changed or not.

查看:80
本文介绍了以编程方式验证晶体报告数据集是否已更改。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些水晶报告,如果数据库表或列发生了变化,那么我需要知道这些报告的数据集是否使用c#代码进行了更改。例如,我可以手动右键单击报表的数据集,然后单击验证数据库。它会说数据库是最新的。我想用c#代码执行相同的操作。请分享您的想法。这是可能的c#代码。



我尝试过:



我使用了VerifyDatabase方法,



I've some crystal reports, If the database table or column changed then I need to know those report's dataset are changed or not using c# code. For example I can manually right clicks the report's dataset then I can click "Verify Database". It will say "The databse is up to date". Same action I want to perform using c# code. Please share your ideas. Is this possible by c# code.

What I have tried:

I used VerifyDatabase method,

var analysisSuccess = true;
          var reportDocumentRc = new ReportDocument();

          try
          {
              this.Cursor = Cursors.WaitCursor;
              reportDocumentRc.Load(reportFileFullName);
              -----> reportDocumentRc.VerifyDatabase();





但它会引发异常,例如登录失败。



but it throws exception like "log on failed".

推荐答案

Crystal Reports不会在报告中保存身份验证详细信息,您必须按如下方式将它们提供给报告;

Crystal Reports do not save authentication details within the Report, you must provide them to the report as follows;
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("Path and Filename of the Report");
// Create a Crystal ConnectionInfo object
CrystalDecisions.Shared.ConnectionInfo conRpt = new ConnectionInfo();
conRpt.ServerName = "DB Server";
conRpt.DatabaseName = "DB Name";
// use the below for SQL authentication
conRpt.IntegratedSecurity = false;
conRpt.UserID = "SQL Username";
conRpt.Password = "SQL Password";
// use the below if using Windows Authentication
// conRpt.IntegratedSecurity = true;

// Apply the connection information to the report tables
CrystalDecisions.CrystalReports.Engine.Tables tblsRpt = rptDoc.Database.Tables;
for(int i = 0; i < tblsTRpt.Count; i++)
{
    CrystalDecisions.CrystalReports.Engine.Table tblRpt = tblsRpt[i];
    CrystalDecisions.Shared.TableLogOnInfo infoTbl = tblRpt.LogOnInfo;
    infoTbl.ConnectionInfo = conRpt;
    tblRpt.ApplyLogOnInfo(infoTbl);
}
// If the Report contains sub reports you need to loop through each sub-report and apply the LogOnInfo to each Sub Report table

// you should now be able to Verify the database
rptDoc.VerifyDataBase();





请注意; VerifyDatabase没有返回值,因此我希望你需要将语句包装在try / catch / finally&自己处理错误



希望这有帮助



Please note; VerifyDatabase does not return a value, hence I would expect that you will need to wrap the statement in a try/catch/finally & handle errors yourself

Hope this helps


这篇关于以编程方式验证晶体报告数据集是否已更改。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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