Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Programatically add columns to .rdlc

Author  Topic 

winseelan
Starting Member

1 Post

Posted - 2008-09-16 : 09:52:38
Hai to all,
I’m using Visual Studio 2005 C# and SQL Server 2005.
I want to use SQL reporting services. I want to add the records prograatically to the .rdlc and display in the reportviewer control, design time I just create empty .rdlc file. So that I download some code from here
http://gotreportviewer.com/DynamicTable.zip
This is only supporting for Text objects if I add the Images from database as byte[] then it displays as #Error so I add some code in
RdlGenerator.cs file
private Rdl.TableCellsType CreateTableCells()
{
Rdl.TableCellsType tableCells = new Rdl.TableCellsType();
tableCells.TableCell = new Rdl.TableCellType[m_fields.Count];
for (int i = 0; i < m_fields.Count; i++)
{
tableCells.TableCell[i] = CreateTableCell(m_fields[i]);
}
return tableCells;
}

private Rdl.TableCellType CreateTableCell(string fieldName)
{
Rdl.TableCellType tableCell = new Rdl.TableCellType();
tableCell.Items = new object[] { CreateTableCellReportItems(fieldName) };
return tableCell;
}

private Rdl.ReportItemsType CreateTableCellReportItems(string fieldName)
{
if (fieldName == "imgData")//This is the Image column
{
Rdl.ReportItemsType reportItems = new Rdl.ReportItemsType();
reportItems.Items = new object[] { CreateTableCellImage(fieldName) };
return reportItems;
}
else
{
Rdl.ReportItemsType reportItems = new Rdl.ReportItemsType();
reportItems.Items = new object[] { CreateTableCellTextbox(fieldName) };
return reportItems;
}
}

private Rdl.TextboxType CreateTableCellTextbox(string fieldName)
{

Rdl.TextboxType textbox = new Rdl.TextboxType();
textbox.Name = fieldName;
textbox.Items = new object[]
{
"=Fields!" + fieldName + ".Value",
CreateTableCellTextboxStyle(),
true,
};
textbox.ItemsElementName = new Rdl.ItemsChoiceType14[]
{
Rdl.ItemsChoiceType14.Value,
Rdl.ItemsChoiceType14.Style,
Rdl.ItemsChoiceType14.CanGrow,
};
return textbox;
}

private Rdl.ImageType CreateTableCellImage(string fieldName)
{

Rdl.ImageType image = new Rdl.ImageType();
image.Name = fieldName;

image.Items = new object[]
{
"=Fields!" + fieldName + ".Value",
//CreateHeaderTableCellIMageStyle(),
true,
};
image.ItemsElementName = new Rdl.ItemsChoiceType15[]
{
Rdl.ItemsChoiceType15.MIMEType,
Rdl.ItemsChoiceType15.Source,
Rdl.ItemsChoiceType15.Value ,
};

return image;
}
But it returns error as below when this code is reached

RdlGenerator.cs
public void WriteXml(Stream stream)
{
XmlSerializer serializer = new XmlSerializer(typeof(Rdl.Report));
serializer.Serialize(stream, CreateReport());
}
{System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Value of ItemsElementName mismatches the type of Rdl.ImageTypeSource; you need to set it to Rdl.ItemsChoiceType15.@Source.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write119_ImageType(String n, String ns, ImageType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write168_ReportItemsType(String n, String ns, ReportItemsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write12_TableCellType(String n, String ns, TableCellType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write13_TableCellsType(String n, String ns, TableCellsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write16_TableRowType(String n, String ns, TableRowType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write17_TableRowsType(String n, String ns, TableRowsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write55_DetailsType(String n, String ns, DetailsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write56_TableType(String n, String ns, TableType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write168_ReportItemsType(String n, String ns, ReportItemsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write199_BodyType(String n, String ns, BodyType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write204_Report(String n, String ns, Report o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReport.Write205_Report(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o)
at Attempt_1.RdlGenerator.WriteXml(Stream stream) in

Experts please give me solution.


Thanks in Advance
   

- Advertisement -