ODBC 的数据库 报表登录和传递参数

 public string ExportToDisk(string reportPath , string paramValue)
        
{
         TableLogOnInfo logOnInfo 
= new TableLogOnInfo();
            logOnInfo.ConnectionInfo.ServerName 
= "SSI";
            logOnInfo.ConnectionInfo.DatabaseName 
= "Report";
            logOnInfo.ConnectionInfo.UserID 
= "sa";
            logOnInfo.ConnectionInfo.Password 
="1";            
            
//设置数据库
            
            ReportDocument RptDoc 
= new ReportDocument();
            RptDoc.Load(reportPath);
            
            
for (int table_count = 0; table_count < RptDoc.Database.Tables.Count; table_count++)
            
{
                RptDoc.Database.Tables[table_count].ApplyLogOnInfo(logOnInfo);
            }

           
// 报表里的表各个都进行登录
            
            RptDoc.Refresh();
           
// 刷新,一定要在数据库登录后进行刷新,不然会出错
            
            
            RptDoc.DataDefinition.ParameterFields[
0].CurrentValues.AddValue(paramValue);
            RptDoc.DataDefinition.ParameterFields[
0].DefaultValues.AddValue(paramValue);
           
// 传递参数,要在刷新之后进行传递,不然传递的参数都会被刷新掉,会报缺少参数值的错误
           
//如果是多个参数,可以做个循环(RptDoc.DataDefinition.ParameterFields.Count)做为判断条件。
            
           
// 剩余的操作是导出报表了,这个大家都会,我就不多说了。
        }
有说错的地方,希望大家指正。呵呵
原文地址:https://www.cnblogs.com/QAnnie/p/1158052.html