本帖最后由 sl641382011 于 2010-05-12 18:25:41 编辑

解决方案 »

  1.   

    SqlConnectionStringBuilder building = new SqlConnectionStringBuilder("/*连接字符串*/");
                TableLogOnInfo logOnInfo = new TableLogOnInfo();
                logOnInfo.ConnectionInfo.ServerName = building.DataSource;
                logOnInfo.ConnectionInfo.DatabaseName = building.InitialCatalog;
                logOnInfo.ConnectionInfo.UserID = building.UserID;
                logOnInfo.ConnectionInfo.Password = building.Password;            for (int i = 0; i < this.crystalReport.Database.Tables.Count; i++)
                {
                    this.crystalReport.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
                }
      

  2.   

    http://topic.csdn.net/u/20090626/17/8090bf70-bed9-41ac-9e09-c0a6a7ab4cb8.html?37757看下这个就知其所以然了。。
      

  3.   

     string sql = "Select * from Customs";
            string DBConfig_sql = @"Data Source=ghost-pc\sql2005;Initial Catalog=Test;User ID=sa;Password=411325;";
            DataSet ds = new DataSet();
            SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
            SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
            SqlDataAdapter sqlAd = new SqlDataAdapter();
            sqlAd.SelectCommand = sqlCmd;
            sqlAd.Fill(ds, "Customs");
            CrystalReportSource1.ReportDocument.Load(Server.MapPath("CR1.rpt"));
            //注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
            CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables["Customs"]);
            //{?}中的参数可以不用赋值,即使赋了值也不起作用。
            CrystalReportSource1.ReportDocument.SetParameterValue("Country", "China");        CrystalReportSource1.DataBind();
            CrystalReportViewer1.ReportSource = CrystalReportSource1;
            CrystalReportViewer1.DataBind();