dds.Fill(ds,"tablename")由于我的是多表联合查询,报表里用的字段也是多个表的,这里如果只填一个表名,报表里其他表里的字段就找不到,提示登录失败
dds.Fill(ds,"tablename1")
dds.Fill(ds,"tablename2")
这样填充后是可以显示,但数据得到的就不是我联合查询后的数据了
直接这样dds.Fill(ds)写也不行!请高手们指教啊!!!!!!

解决方案 »

  1.   

    如果你用的是水晶报表的推模式,一般不用设置登陆信息,但是要这样写:obj.SetDataSource(this.ds.Tables["tablename"]);如果你写成了obj.SetDataSource(this.ds)就会有登陆框的。 如果你用的是水晶报表的拉模式,你就一定要写上登陆信息:crReportDocument = new OracleReport();   //Set the crConnectionInfo with the current values stored in the report
       crConnectionInfo = crReportDocument.Database.Tables[0].LogOnInfo.ConnectionInfo;   /* Populate the ConnectionInfo Objects Properties with the appropriate values for
       the ServerName, User ID, Password and DatabaseName. However, since Oracle 
       works on Schemas, Crystal Reports does not recognize or store a DatabaseName. 
       Therefore, the DatabaseName property must be set to a BLANK string. */
       crConnectionInfo.DatabaseName = "";
       crConnectionInfo.ServerName = "Your Server Name";
       crConnectionInfo.UserID = "Your User ID";
       crConnectionInfo.Password = "Your Password";   //Set the CrDatabase Object to the Report's Database
       crDatabase = crReportDocument.Database;   //Set the CrTables object to the Tables collection of the Report's dDtabase
       crTables = crDatabase.Tables;   //Loop through each Table object in the Tables collection and apply the logon info
       //specified ealier. Note this sample only has one table so the loop will only execute once
       foreach (Table crTable in crTables)
       {
        crTableLogOnInfo = crTable.LogOnInfo;
        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
        crTable.ApplyLogOnInfo (crTableLogOnInfo);    // if you wish to change the schema name as well, you will need to set Location property as follows:
        // crTable.Location = "<new schema name>." + crTable.Name;
       }   //Set the ReportSource of the CrystalReportViewer to the strongly typed Report included in the project
       crystalReportViewer1.ReportSource = crReportDocument; 还有一点要注意:
    如果你用到了子报表,一定要处理://Go through each sections in the main report and identify the subreport by name
       crSections = crReportDocument.ReportDefinition.Sections;   foreach(Section crSection in crSections)
       {
        crReportObjects = crSection.ReportObjects;
        //loop through all the report objects to find all the subreports
        foreach(ReportObject crReportObject in crReportObjects)
        {
         if (crReportObject.Kind == ReportObjectKind.SubreportObject)
         {
          //you will need to typecast the reportobject to a subreport 
          //object once you find it
          crSubreportObject = (SubreportObject)crReportObject;      //open the subreport object
          crSubReportDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
          //Once the correct subreport has been located pass it the 
          //appropriate dataset
          if(crSubReportDoc.Name == "FirstSub") 
          {
           //crSubReportDoc.Database.Tables[0].SetDataSource(ds);
           crSubReportDoc.SetDataSource(ds);
          }
         }
        }
       }
       crystalReportViewer1.ReportSource = crReportDocument;同样crSubReportDoc.SetDataSource(ds);改为:crSubReportDoc.SetDataSource(ds.Tables["tablename"]); 
      

  2.   

    .........但是我的是多表联合查询,有多个表的字段啊...crSubReportDoc.SetDataSource(ds.Tables["tablename"]);这只写一个表还是不行啊
      

  3.   

    最好重新建立一个和你报表字段都相同的xsd文件,把所要的数据处理好填入,这个xsd就是你报表的数据源,然后再用我上面的方法,应该就可以了.可以下这个看看,
    http://www.njpro.cn/20069/ShowPost.aspx
      

  4.   

    我建好了xsd文件啊,报表的字段就是从xsd拖的。。但是我填充dataset的时候
    dds.Fill(ds,"tablename") 只添一个表就会报错。。
    dds.Fill(ds,"tablename1")
    dds.Fill(ds,"tablename2")
    这样吧所有的表都填充了就可以显示,但是数据又不对,不是正确的数据
      

  5.   

    但是由于我是多表联合查询,返回的字段是多个表的,运行后,提示登录失败...
    这样写的
    sql="select a.* ,b.* from aa a left join bb b on a.id=b.id"
    ......
    dds.Fill(ds,"aa")
      

  6.   

    不要这样做,重新建立一个表结构,和你的xsd文件中的表一样,然后把你多表连接查询的结果得到的dds重新处理后,防入xsd:列如:dss=new DataSet();
    //新建表结构
    DataTable dt=new DataTable("clyfhzb");//表名字必须和你的xsd文件中一张表名一样
    dt.Columns.Add("trq",System.Type.GetType("System.DateTime"));
    dt.Columns.Add("ccph",System.Type.GetType("System.String"));
    dt.Columns.Add("njs",System.Type.GetType("System.Int32"));
    dt.Columns.Add("nyf",System.Type.GetType("System.Decimal"));
    dt.Columns.Add("nmjyf",System.Type.GetType("System.Decimal"));
    dss.Tables.Add(dt); //添加到数据集中
    这个表结构和你xsd文件中的某张表一样,
    <xs:element name="clyfhzb">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="trq" type="xs:dateTime" />
    <xs:element name="ccph" type="xs:string" />
    <xs:element name="njs" type="xs:int" />
    <xs:element name="nyf" type="xs:decimal" />
    <xs:element name="nmjyf" type="xs:decimal" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>然后添加数据:
    //为数据集添加数据,
    for(int i=0;i<this.ds.Tables["clyfhzb"].Rows.Count;i++)  //this.ds.Tables["clyfhzb"]就是你连接查询的得到的ds,
    {
    DataRow dr=dt.NewRow();
    dr["trq"]=ds.Tables["clyfhzb"].Rows[i]["tccsj"];
    dr["ccph"]=ds.Tables["clyfhzb"].Rows[i]["ccph"];
    dr["njs"]=ds.Tables["clyfhzb"].Rows[i]["nchjs"];
    dr["nyf"]=ds.Tables["clyfhzb"].Rows[i]["yf"];
    // if(System.Convert.ToInt32(dr["njs"].ToString())==0||System.Convert.ToDecimal(dr["nyf"].ToString())==0)
    // {
    // dr["nmjyf"]=0;
    // }
    // else
    // {
    dr["nmjyf"]=System.Convert.ToDecimal(dr["nyf"].ToString())/System.Convert.ToInt32(dr["njs"].ToString());
    // }
    dt.Rows.Add(dr);
    }
      

  7.   

    或者这种做法麻烦了一些,但是比较清楚。如果你不想这么做,你必须要保证你连接查询的得到的ds和你的xsd文件表一模一样即可。
    我想会不会是你的结构不一样,或者表字段名称不一样引起错误的。
      

  8.   

    啊..我的xsd里有多张表...这样是不是不行?只能做一张表么
      

  9.   

    我想问下..xsd里的表是不是只起到绑定字段的作用.和具体的数据没有关系?我查询有多张表,我吧所需要的字段做一个新的XSD是不是就可以了?
      

  10.   

    lyb_abiandbel(渴望成为高手)大哥还再吗
      

  11.   

    我想问下..xsd里的表是不是只起到绑定字段的作用.和具体的数据没有关系?我查询有多张表,我吧所需要的字段做一个新的XSD是不是就可以了?
    ------------------------------------我想应该是的!如果你不想做,保证你的填入ds的表的格式和你xsd的格式一样就可以了。