I have a List<Customer> which is a linq object from a table. I want to generate a letter per customer by iterating through this list and writing a PDF to disc.
I want to use Crystal Reports, in the database expert I have chosen .Net Objects and selected my Linq.Customer object as the source. This shows all my fields as expected and I can create the report fine.
I am getting the exception “Data Source is not valid”
This is my code
public void GenerateLetters(List<Customer> customers){
foreach(Customer cust in customers){
this.Generate(cust);
}
}
Where Generate() is:
public Generate(Customer cust){
// this is the crystal reports letter
Letter letter = new Letter();
// set data source
letter.SetDataSource(cust); // exception thrown here
// get the pdf stream
pdfStream = (MemoryStream)letter.
ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
// copy to byte array
fileBytes = pdfStream.ToArray();
// clean up
pdfStream.Close();
letter.Dispose();
}
I am getting the exception on setting the Data source, does anyone have any ideas?
I’m not very familiar to Crystal but try to pass a
List<Customer>as datasource: