Reg : An element is bound to the data source 'MyModel' which has not been provided any data

0
sakthiaseer posted this 28 April 2022

Dear Team,

I am binding .Net Data source to my template. But i am getting above subjected error. Please find image link below.

 // Get the customer object with the Id = 15.
        InvoiceModel customer = new InvoiceModel()
        {
            Amount = 100,
            CustomerAddress = "4/46, uppupalayam east",
            CustomerName = "Sakthi",
            InvoiceComment = " Test Comment",
            InvoiceDate = DateTime.Now,
            InvoiceRef = "REF1234",
            PaidAmount = 2000,
            ProductName = "Metformin 500",
            Qty = 1000,
            TaxAmount = 100,
            UnitCost = 2
        };

        IEnumerable<invoicemodel> invoiceModels = new List<invoicemodel>() { customer };

        // Create a temporary file for the generated report document.
        string reportDocumentTemplate = @"C:\Users\User\Documents\DocentricInvoiceTemplate.docx";
        string reportDocumentReport = @"C:\Users\User\Documents\DocentricInvoiceReport.docx";
        using (Stream reportDocumentStream = File.Create(reportDocumentReport))
        {
            // Open the report template file.
            using (Stream reportTemplateStream = new FileStream(reportDocumentTemplate, FileMode.Open))
            {
                // Generate the report document using 'DocumentGenerator'.
                DocumentGenerator dg = new DocumentGenerator(invoiceModels.First());
                DocumentGenerationResult result = dg.GenerateDocument(reportTemplateStream, reportDocumentStream);
                if (result.HasErrors)
                {
                    //foreach (Word.Error error in result.Errors) Console.Out.WriteLine(error.Message);
                }
            }
        }

        return reportDocumentReport;

Regards, Sakthi

1 Posts
1 Points
1 Comments
Order By: Standard | Newest | Votes
0
jles posted this 28 April 2022

Hi Sakthti,

Thank you for your email. I checked your solution and found the following problems: 1. In your template, you have added a second data source named “InvoiceModel” for you are not providing a value in your C# code when generating a report. You could do so by calling the DocumentGenerator.SetNamedDataSourceValue method. Still, having a secondary data source seems unnecessary in your case, as you can use the default one. To fix this, just remove your named data source, and use the default one. You will need to rebind everything, though. 2. Your data source, as defined in the template, expects a value of type DoccentricConsoleApp.InvoiceModel. It is a mistake to wrap your object into a list. Just pass the object itself as the data source.

Let me know if this helps.

Regards, Jure

155 Posts
295 Points

Our 229035 members have posted 345 times in 102 discussions