cancel
Showing results for 
Search instead for 
Did you mean: 

Change XSD / XML dataset during runtime and display texts in field explorer

Former Member
0 Kudos

Hi there,

I am changing the datasource of a report during runtime. Afterwards, I would like to change the texts of the fields appearing in the field explorer.

I tried:

CrystalDecisions.ReportAppServer.DataDefModel.XMLDataSetClass xmlDS =

new CrystalDecisions.ReportAppServer.DataDefModel.XMLDataSetClass();

byte[] xmlContent = reportContent.getXmlContent();

byte[] xsdContent = reportContent.getXsdContent();

CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray xmlData =

new CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray();

CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray xsdData =

new CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray();

xmlData.ByteArray = xmlContent;

xmlDS.XMLData = xmlData;

xsdData.ByteArray = xsdContent;

xmlDS.XMLSchema = xsdData;

rasDoc.DatabaseController.SetDataSource(xmlDS, "", "");

rasDoc.Database.Tables[0].Description = "POMMES";

for (int i = 0; i < rasDoc.DatabaseController.Database.Tables[0].DataFields.Count; i++)

{

rasDoc.Database.Tables[0].DataFields.Name = "TEST";

MessageBox.Show(rasDoc.Database.Tables[0].DataFields.Name);

rasDoc.Database.Tables[0].DataFields.HeadingText = "HOORAY";

rasDoc.Database.Tables[0].DataFields.Description = "NOPE";

MessageBox.Show(rasDoc.Database.Tables[0].DataFields.Description);

MessageBox.Show(rasDoc.Database.Tables[0].DataFields.HeadingText);

}

When running this, the message boxes include the right strings I set before but when this is done, the filed explorer still shows no changes. What am I doing wrong?

Also, I would like to change the field texts that are displayed in the field explorer. How can this be done?

Thanks,

Pascal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

RAS can be funny about applying table changes. Have you tried cloning the table, setting the changes, then replacing the table on the report with the cloned one? That's the usual process for making a change to a table.

As for the field explorer, it will pick up whatever settings the table has. There's no separate property for what gets displayed in the field explorer. The closest thing would probably be aliases for the table name and fields.

Former Member
0 Kudos

Hi Trista,

could you please specify this a little bit more? How would you clone the dataset what are the calls to exchange it? Do you have a code snippet for me, please?

I not only try to replace the dataset but also change the display names that are used in the field explorer. So far I encountered the following problems, maybe you have an idea about this:

- using a xml dataset, the names shown in the field explorer are only the xml schma names but no additional descriptions are possible to set

- using an ADO dataset, I still need an XSD file to be read

- no "simple" Table can be used

Thanks,

Pascal

Former Member
0 Kudos

Also, I do not understand why I am not able to change the display of the fields in the filed explorer.

This coding does not change a bit, but why??


//preparation
string tableName = reportDataSet.Tables[0].TableName;
              // Get the table definition exactly like the definition of my own dataset.
              CrystalDecisions.ReportAppServer.DataDefModel.Table table = GetTable(tableName);
              table.ConnectionInfo = connectionInfo;

              //delete all existing tables if there are any
              foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table oldTable in rasDoc.DatabaseController.Database.Tables)
                  rasDoc.DatabaseController.RemoveTable(oldTable.Name);
              
              
              //add my new table with the IDs of the XSD
              rasDoc.DatabaseController.AddTable(table, null);

              //now I want to change the displayed fields texts
              CrystalDecisions.ReportAppServer.DataDefModel.Tables modifyTables = 
                  rasDoc.DatabaseController.Database.Tables;

              CrystalDecisions.ReportAppServer.DataDefModel.Table myTable =
                  (CrystalDecisions.ReportAppServer.DataDefModel.Table)modifyTables[0];
              Fields fields = myTable.DataFields;

              for (int i = 0; i < fields.Count; i++)
              {
                  ISCRField field = fields<i>;
                  
                  ResultFieldController resultFieldController =
                     rasDoc.DataDefController.ResultFieldController;
                  try
                  {
                      resultFieldController.Remove(field);
                      string sText = "";
                      sText = "Bäschreibung" + i.ToString();
                      field.Description = new string(sText.ToCharArray());

                      sText = "Häding" + i.ToString();
                      field.HeadingText = new string(sText.ToCharArray());
                     
                      //sText = "Näme" + i.ToString();
                      //field.Name = new string(sText.ToCharArray());
                      
                      resultFieldController.Add(-1, field);
                  }
                  catch (Exception exp)
                  {
                      MessageBox.Show(exp.Message);
                  }
              }

I am completely stuck.

Thanks for any help.

Pascal

Edited by: Pascal Schmidt-Volkmar on Sep 30, 2008 9:31 AM

Former Member
0 Kudos

Even if I try to set the field texts displayed in the field explorer when reading my dataset, it does not work:


        private CrystalDecisions.ReportAppServer.DataDefModel.Table GetTable(string tableName)
        {
            CrystalDecisions.ReportAppServer.DataDefModel.Table table = 
                new CrystalDecisions.ReportAppServer.DataDefModel.Table();
            //It is crucial to set table.Name as it should never be empty!!
            table.Name = "tableName";
            //table.Alias is the only value of the table shown in field explorer
            table.Alias = "Can_be_set_in_code";
            //don't touch this, as the qualified name is used for assigning and searching values
            table.QualifiedName = tableName;
            //table.Description = "Desc";

            var fields = new Fields();

            var dbField = new DBField();
            var fieldName = "ID";
            //any changes to description or heading text will either result in the error that the field cannot
            /be found anymore or no changes happen
            dbField.Description = fieldName;
            dbField.HeadingText = fieldName;
            dbField.TableAlias = "Table_Alias";
            dbField.Name = fieldName;
            dbField.Type = CrFieldValueTypeEnum.crFieldValueTypeInt64sField;
            fields.Add(dbField);
            
            table.DataFields = fields;
            return table;
        }

Pascal

Answers (1)

Answers (1)

Former Member
0 Kudos

OK, solved.

BR,

Pascal