We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to reference fields in DataTables within DataSet

I have a business case where I have a generic Letter template, in which I insert a building block Word document for the content.
I have generic data (Addressee, Date, Reference etc) and custom data, depending on the building block that is inserted.
I have created a DataSet named ‘ds’ with two tables ‘Generic’ and ‘Specific’, each with one row.
To use ReportingEngine, do I need to pass the dataSourceName parameter to BuildReport, and what is the syntax for the expression in my tags? (I tried things like << [ds.Generic.Rows[0].Name] >> and several other variations.

Best regards,
Tim

@TimDol You can use First() or FirstOrDefault() to access the first row of the DataTable. For example see the following simple code:

DataSet ds = new DataSet("ds");
DataTable generic = new DataTable("Generic");
generic.Columns.Add("FirstName");
generic.Columns.Add("LastName");
generic.Rows.Add(new string[] { "Alexey", "Noskov" });

ds.Tables.Add(generic);

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("<<[ds.Generic.First().FirstName]>>");
builder.Writeln("<<[ds.Generic.FirstOrDefault().LastName]>>");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, ds, "ds");
doc.Save(@"C:\Temp\out.docx");
1 Like