none
Microsoft report viewer RRS feed

  • Question

  • I have made a RDLC file by underneath code, and then I used it together with a microsoft report viewer to show my tables but repeated items left blank (there are many WHITE cells in the result).

    the code:

    //Make a RDLC file.//
                //Open a new RDLC file stream for writing
                FileStream stream;
                stream = File.Create(@"C:\Reports\Report1.rdlc");
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);

                //Causes child elements to be indented.
                writer.Formatting = Formatting.Indented;

                //Report element
                writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                writer.WriteStartElement("Report");
                writer.WriteAttributeString("xmlns", null,
                    "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
                writer.WriteElementString("Width", "10cm");

                //DataSource element
                writer.WriteStartElement("DataSources");
                writer.WriteStartElement("DataSource");
                writer.WriteAttributeString("Name", null, "ACE-PC");
                writer.WriteStartElement("ConnectionProperties");
                writer.WriteElementString("DataProvider", "SQL");
                writer.WriteElementString("ConnectString", ConnectionString);
                writer.WriteElementString("IntegratedSecurity", "true");
                writer.WriteEndElement(); // ConnectionProperties
                writer.WriteEndElement(); // DataSource
                writer.WriteEndElement(); // DataSources

                // DataSet element
                writer.WriteStartElement("DataSets");
                writer.WriteStartElement("DataSet");
                writer.WriteAttributeString("Name", null, "objDataSet");

                // Query element
                writer.WriteStartElement("Query");
                writer.WriteElementString("DataSourceName", "ACE-PC");
                writer.WriteElementString("CommandType", "Text");
                writer.WriteElementString("CommandText", CommandText);
                writer.WriteElementString("Timeout", "30");
                writer.WriteEndElement(); // Query

                // Fields elements
                writer.WriteStartElement("Fields");
                foreach (string fieldName in m_fields)
                {
                    writer.WriteStartElement("Field");
                    writer.WriteAttributeString("Name", null, fieldName);
                    writer.WriteElementString("DataField", null, fieldName);
                    writer.WriteEndElement();// Field
                }

                // End previous elements
                writer.WriteEndElement(); // Fields
                writer.WriteEndElement(); // DataSet
                writer.WriteEndElement(); // DataSets

                // Body element
                writer.WriteStartElement("Body");
                writer.WriteElementString("Height", "5cm");

                // ReportItems element
                writer.WriteStartElement("ReportItems");

                // Table element
                writer.WriteStartElement("Table");
                writer.WriteAttributeString("Name", null, "Table1");
                writer.WriteElementString("DataSetName", "objDataSet");
                writer.WriteElementString("Top", ".5in");
                writer.WriteElementString("Left", ".5in");
                writer.WriteElementString("Height", ".5in");
                writer.WriteElementString("Width", (m_fields.Count * 1) + "in");

                // Table Columns
                writer.WriteStartElement("TableColumns");
                for (int i = 0; i < m_fields.Count; i++)
                {
                    writer.WriteStartElement("TableColumn");
                    writer.WriteElementString("Width", "2.5cm");
                    writer.WriteEndElement(); // TableColumn
                }
                writer.WriteEndElement(); // TableColumns

                // Header Row
                writer.WriteStartElement("Header");
                writer.WriteStartElement("TableRows");
                writer.WriteStartElement("TableRow");
                writer.WriteElementString("Height", ".25in");
                writer.WriteStartElement("TableCells");

                foreach (string fieldName in m_fields)
                {
                    writer.WriteStartElement("TableCell");
                    writer.WriteStartElement("ReportItems");

                    //Textbox
                    writer.WriteStartElement("Textbox");
                    writer.WriteAttributeString("Name", null, "Header" + fieldName);

                    writer.WriteStartElement("Style");
                    writer.WriteElementString("TextDecoration", "Underline");
                    writer.WriteEndElement(); // Style

                    writer.WriteElementString("Top", "0in");
                    writer.WriteElementString("Left", "0in");
                    writer.WriteElementString("Height", ".25in");
                    writer.WriteElementString("Width", ".25in");
                    writer.WriteElementString("Value", fieldName);
                    writer.WriteEndElement(); // Textbox

                    writer.WriteEndElement(); // ReportItems
                    writer.WriteEndElement(); // TableCell
                }
                writer.WriteEndElement(); // TableCells
                writer.WriteEndElement(); // TableRow
                writer.WriteEndElement(); // TableRows
                writer.WriteEndElement(); // Header

                // Details Row
                writer.WriteStartElement("Details");
                writer.WriteStartElement("TableRows");
                writer.WriteStartElement("TableRow");
                writer.WriteElementString("Height", ".25in");
                writer.WriteStartElement("TableCells");
                foreach (string fieldName in m_fields)
                {
                    writer.WriteStartElement("TableCell");
                    writer.WriteStartElement("ReportItems");

                    // Textbox
                    writer.WriteStartElement("Textbox");
                    writer.WriteAttributeString("Name", null, fieldName);

                    writer.WriteStartElement("Style");
                    writer.WriteStartElement("BorderColor");
                    writer.WriteElementString("Default", "LightGrey");
                    writer.WriteEndElement();//BorderColor

                    writer.WriteStartElement("BorderStyle");
                    writer.WriteElementString("Default", "Solid");
                    writer.WriteEndElement();//BorderStyle
                    writer.WriteEndElement(); // Style

                    writer.WriteElementString("Top", "0in");
                    writer.WriteElementString("Left", "0in");
                    writer.WriteElementString("Height", ".25in");
                    writer.WriteElementString("Width", ".25in");
                    writer.WriteElementString("Value", "=Fields!" + fieldName + ".Value");
                    writer.WriteElementString("HideDuplicates", "objDataSet");
                    writer.WriteElementString("CanGrow", "true");

                    writer.WriteEndElement(); // Textbox

                    writer.WriteEndElement(); // ReportItems
                    writer.WriteEndElement(); // TableCell
                }
                // End Details element and children  
                writer.WriteEndElement(); // TableCells
                writer.WriteEndElement(); // TableRow
                writer.WriteEndElement(); // TableRows
                writer.WriteEndElement(); // Details

                // End table element and end report definition file
                writer.WriteEndElement(); // Table
                writer.WriteEndElement(); // ReportItems
                writer.WriteEndElement(); // Body
                writer.WriteEndElement(); // Report

                // Flush the writer and close the stream
                writer.Flush();
                stream.Close();

     

    plz help me!

    Wednesday, October 6, 2010 5:51 AM