By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

Programatically add columns to .rdlc

P: 1
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.XmlS erializationWriterReport.Write119_ImageType(String n, String ns, ImageType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write168_ReportItemsType( String n, String ns, ReportItemsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write12_TableCellType(Str ing n, String ns, TableCellType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write13_TableCellsType(St ring n, String ns, TableCellsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write16_TableRowType(Stri ng n, String ns, TableRowType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write17_TableRowsType(Str ing n, String ns, TableRowsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write55_DetailsType(Strin g n, String ns, DetailsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write56_TableType(String n, String ns, TableType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write168_ReportItemsType( String n, String ns, ReportItemsType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write199_BodyType(String n, String ns, BodyType o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write204_Report(String n, String ns, Report o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterReport.Write205_Report(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(S tream stream, Object o)
at Attempt_1.RdlGenerator.WriteXml(Stream stream) in
d:\\project

I came to know the same taks is possible by the following code

Microsoft.ReportingServices.ReportRendering.TextBo x t1 = new Microsoft.ReportingServices.ReportRendering.TextBo x();
Microsoft.ReportingServices.ReportRendering.Image i1 = new Microsoft.ReportingServices.ReportRendering.Image( );
Ref:http://bytes.com/forum/thread446027.html
but i dont know the complete code.
Experts please post sample code.
Sep 16 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.