Description:
I have a report with an untyped data set as a data source. I serialize the report to XML and then restore it but the data source is empty. How to resolve this?
Answer:
The following data sources provide built-in serialization:
Since the Web Report Designer works with the XML report representation, incorrect results may be produced after you load a report which uses an untyped data set as a data source.
We need to serialize an untyped data source to resolve the issue.
To do so, implement a serializer which implements the DevExpress.XtraReports.Native.IDataSerializer interface and use the XML-serialization capabilities exposed by the DataSet class to serialize/deserialize this data set as follows.
In the IDataSerializer.Serialize method, serialize a DataSet into XML through the DataSet.WriteXml (or DataSet.GetXml) method.
In the IDataSerializer.Deserialize method, create a new DataSet instance and populate it from a properly formatted XML stream by using the DataSet.ReadXml method.
Here is sample code.
C#public class CustomUntypedDataSetSerializer : IDataSerializer {
public const string Name = "CustomUntypedDataSetSerializer";
public bool CanSerialize(object data, object extensionProvider) {
return (data is DataSet);
}
public string Serialize(object data, object extensionProvider) {
if (data is DataSet) {
DataSet ds = data as DataSet;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
XmlWriter writer = XmlWriter.Create(sb);
ds.WriteXml(writer, XmlWriteMode.WriteSchema);
return sb.ToString();
}
return string.Empty;
}
public bool CanDeserialize(string value, string typeName, object extensionProvider) {
return typeName == "System.Data.DataSet";
}
public object Deserialize(string value, string typeName, object extensionProvider) {
DataSet ds = new DataSet();
using (XmlReader reader = XmlReader.Create(new StringReader(value))) {
ds.ReadXml(reader, XmlReadMode.ReadSchema);
}
return ds;
}
}
Initialize the custom serializer using the SerializationService.RegisterSerializer
method at the application start.
C#//in the static form constructor
static Form1() {
SerializationService.RegisterSerializer(CustomUntypedDataSetSerializer.Name, new CustomUntypedDataSetSerializer());
}
//when initializing a report
void InitReport(){
//...
report.Extensions[SerializationService.Guid] = CustomUntypedDataSetSerializer.Name;
//...
}
This solution is illustrated by the following examples.
How to serialize a report with an untyped data set as a data source (for the ASP.NET platform)
How to serialize a report to XML with an untyped data set as a data source (for the WinForms platform).
See also:
WinForms: How to implement custom XML serialization of a report that is bound to a dataset
Web: Web Report Designer - How to use the custom serializer class (IDataSerializer) to serialize the XPO data source to make it visible in the web report designer
Nice article.
My pleasure.
Should you have additional questions, we are always here to assist you.
Thanks,
Jannet
I use ReportDesigner to design a report . But I can not show DataSoure of my report like in the picture attached.
Please help me ! I use ASP.NET MVC 5
Hello,
To process your recent inquiry more efficiently, I've created a separate ticket on your behalf (T371384: Data columns are not populated in the Field List when DataSet is used as a data source). It has been placed in our processing queue and will be answered shortly.
Hi Jannet
Thanks for this code, I´m using and works, but it is very slow when the dataset has a lot of tables and data and the user try to expand the datasource. How can improve the performance?
Hi Jean,
I see that you have already created a separate thread for this issue: T599429: ASPxReportDesigner is very slow expanding datasource. So, lets continue discussing this issue in that thread to avoid discussing the same problem in multiple threads.
Hi!
This is my problem too. This code too slow, when I use large dataset.
I want to see T599429 issue, but I get a "You can't view this ticket" message.
Hi Gábor,
The T599429 ticket is private, and that's why you can't see it. In any case, it may appear that your scenario is different that the one described there. Let's discuss your particular use case in a separate thread I've created on my behalf: XtraReport - a custom DataSet serializer is slow for a large number of rows.
Is it possible to serialize a DataSet for Angular report viewer? Or it won't be able to deserialize it back because custom deserializer method exists only in .net part?
Hi Artyom,
The server-side part of our Reporting components always uses .NET, so the information provided in this article is relevant for Angular applications. The serialization and deserialization are always performed in the server-side code.
If you face any difficulties using this approach in your Angular project, feel free to submit a separate ticket and describe the issue in greater detail. This way, we will be able to research it and provide you with our recommendations on how to resolve it.