看下面的例子:ReportDocument Report = new ReportDocument();
Report.Load(Server.MapPath("\\report\\CrystalReport1.rpt"));
TableLogOnInfo logOnInfo = new TableLogOnInfo();
//对报表中的每个表进行循环
for(int i=0;i==Report.Database.Tables.Count-1;i++)
{
logOnInfo.ConnectionInfo.UserID = "sa";
logOnInfo.ConnectionInfo.Password = "password";
Report.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
}
CrystalReportViewer1.ReportSource = Report;
CrystalReportViewer1.BestFitPage = true;
CrystalReportViewer1.DataBind();希望能对你有所帮助.

解决方案 »

  1.   

    我以前用上面的方法也不行,后来我是这么解决的:
    1.首先在你的项目里加入一个dataset文件,在服务器管理器里连接你的表,拖到dataset里。
    2.在crystalreport1里,选择项目数据-》Ado.net数据集建立报表
    3.在你的page_load中加入如下代码ds1=new DataSet();
    Adapter1.Fill(cw_ds,"table1");
    CrystalReport1 orp=new CrystalReport1();
    orp.SetDataSource(cw_ds);
    this.CrystalReportViewer1.ReportSource=orp;
      

  2.   

    还是不行啦,PULL模式下的水晶报表,根据飞刀的文章(中)做的,并且已加了qz4365(冷风清扬) 的那段代码了的,但是对有密码的数据库还是会“登录失败”,再次请已经通过的朋友介绍介绍,谢谢!
    Wurd(Wurd)说的好像是PUSH模式的水晶报表吧,这种模式好不好控制报表的格式呀?
      

  3.   

    要不试试我的代码:
     Me.CrystalReportViewer1.ReportSource = Server.MapPath("report/scjh_pc_query.rpt")
            Me.CrystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.UserID = "sa"
            Me.CrystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.Password = ""        Me.CrystalReportViewer1.BestFitPage = True
            Me.CrystalReportViewer1.DataBind()
      

  4.   

    to  ketao_78(春来江水绿如蓝): 谢谢你,但你这是针对没有密码的数据库的,这个我已经搞定了的,我现在是想针对有密码的数据库,PULL模式的水晶报表的代码。
    请高手们继续指导!!
      

  5.   

    u db's login type is right?
    I use winNT type,it also give me this error
    hope this for u reference
      

  6.   

    根据Wurd(Wurd)大侠的提示,已经搞定。按飞刀文章的说法,这种应该叫PUSH模式的水晶报表。
    PULL模式的报表,我看有许多人都是用qz4365(冷风清扬)介绍的代码通过的,我怎样试都不行!唉,不过有一种PUSH模式的用就已经不错了。谢谢各位朋友的热心帮助,结帐了,分不多,望笑纳!