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. |
These steps assume that you have already created a report viewer form project and added a report (NewActiveReport1 by default).
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste ABOVE the Form Load event. |
Copy Code |
---|---|
Dim WithEvents rpt As NewActiveReport1 |
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code |
---|---|
Dim 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.Document |
To write the code in C#
C# code. Paste INSIDE the Form Load event. |
Copy Code |
---|---|
System.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; |
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste BELOW the Form Load event. |
Copy Code |
---|---|
Private 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 Sub |
To write the code in C#
C# code. Paste BELOW the Form Load event. |
Copy Code |
---|---|
void 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>. |