When you use an XML data source to supply data to the Barcode control, the control is unable to automatically detect the data type of the XML node. For this reason, you can use the DataType attribute of the XML node to specify string, double, or date time data.
![]() |
If you have a numeric field with leading zeroes that you need to use with the Barcode control, specify a string DataType to avoid clipping the zeroes. |
To specify a string DataType for an XML node and assign it to a barcode
These steps assume that you have already created a report viewer form project and added a report (NewActiveReport1 by default).
- In the design view of the viewer form, double-click the title bar to open the code view and create a Form Load event.
- If you are using Visual Basic, paste code like the following above the Form Load event to create a new instance of your report and access its events (in C#, the code is inside the event in the following step):
To write the code in Visual Basic.NET Visual Basic.NET code. Paste ABOVE the Form Load event.
Copy CodeDim WithEvents rpt As NewActiveReport1
- Paste code like the following inside the Form Load event to create an XML data source, assign it to the report, access the report's FetchData event, and display the report in the viewer:
To write the code in Visual Basic.NET Visual Basic.NET code. Paste INSIDE the Form Load event.
Copy CodeDim xdoc As New System.Xml.XmlDocument() Dim xmlsource As String = "<prj>" + _ "<bcData>0003456</bcData>" + _ "<bcData>0003457</bcData>" + _ "<bcData>0003458</bcData>" + _ "<bcData>0003459</bcData>" + _ "</prj>" rpt = New rptEmpty() Dim xds As New DataDynamics.ActiveReports.DataSources.XMLDataSource() xds.RecordsetPattern = "//prj/" xds.LoadXML(xmlsource) rpt.DataSource = xds rpt.Run() Viewer1.Document = rpt.DocumentC# code. Paste INSIDE the Form Load event.
Copy CodeSystem.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); string xmlsource = "<prj>" + "<bcData>0003456</bcData>" + "<bcData>0003457</bcData>" + "<bcData>0003458</bcData>" + "<bcData>0003459</bcData>" + "</prj>"; rptEmpty rpt = new rptEmpty(); DataDynamics.ActiveReports.DataSources.XMLDataSource xds = new DataDynamics.ActiveReports.DataSources.XMLDataSource(); xds.RecordsetPattern = "//prj/"; xds.LoadXML(xmlsource); rpt.DataSource = xds; rpt.FetchData += new DataDynamics.ActiveReports.ActiveReport.FetchEventHandler(rpt_FetchData); rpt.Run(); viewer1.Document = rpt.Document; - Paste code like the following below the Form Load event to create a FetchData event for the report, access the XML data source, and pass in the string DataType attribute:
To write the code in Visual Basic.NET Visual Basic.NET code. Paste BELOW the Form Load event.
Copy CodePrivate Sub rpt_FetchData(ByVal sender As Object, ByVal eArgs As DataDynamics.ActiveReports.ActiveReport.FetchEventArgs) Handles rpt.FetchData Try Dim r As DataDynamics.ActiveReports.ActiveReport Dim d As DataDynamics.ActiveReports.DataSources.XMLDataSource r = CType(sender, DataDynamics.ActiveReports.ActiveReport) d = CType(r.DataSource, DataDynamics.ActiveReports.DataSources.XMLDataSource) Dim attr As System.Xml.XmlAttribute = d.Document.CreateAttribute("DataType") attr.Value = "string" d.NodeList(d.CurrentPosition).Attributes.Append(attr) Catch eArgs.EOF = True End Try End SubC# code. Paste BELOW the Form Load event.
Copy Codevoid rpt_FetchData(object sender, DataDynamics.ActiveReports.ActiveReport.FetchEventArgs eArgs) { try { DataDynamics.ActiveReports.ActiveReport r = sender as DataDynamics.ActiveReports.ActiveReport; DataDynamics.ActiveReports.DataSources.XMLDataSource d = r.DataSource as DataDynamics.ActiveReports.DataSources.XMLDataSource; System.Xml.XmlAttribute attr = d.Document.CreateAttribute("DataType"); attr.Value = "string"; d.NodeList[d.CurrentPosition].Attributes.Append(attr); } catch { eArgs.EOF = true; } }
Note: When you run this code, it transforms each <bcData>0003456</bcData> node into <bcData DataType="string">0003456</bcData>.
- Open the design view of NewActiveReport1 and from the ActiveReports 6 section of the Toolbox, drag a Barcode control and drop it onto the report.
- Barcode1 is selected in the Properties grid by default. In the DataField property enter . (a period) to assign the node to the barcode.
Concepts
BarCodes
Hide All

