少想,多做!
随笔- 11  文章- 2  评论- 36 
博客园  首页  新随笔  联系  管理  订阅 订阅

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)做为判断条件。
            
           
// 剩余的操作是导出报表了,这个大家都会,我就不多说了。
        }
有说错的地方,希望大家指正。呵呵
posted @ 2008-04-17 14:34 Annie 阅读(168) 评论(1) 编辑 收藏
刷新评论刷新页面返回顶部
程序员问答社区,解决您的IT难题
博客园首页博问新闻闪存程序员招聘知识库
Copyright ©2012 Annie