Loading FastReport from DataTable
Hi everyone, I'm new with Fast Reports and so far I have found it to be very easy to use. I just ran into an issue and can't find a solution anywhere.
I have made a report in the designer using a SQL Database Connection. This works well, but I actually need to manupulate some of the data in my application first.
My intention is to us the same SQL statement to get the data, edit some fields and then I would like to send the DataTable to the report to load rather than have it pull directly from the SQL Database.
How would I do this? I've found where I can pass the connection string and sql statement, but I haven't found any other options for passing anything else to the report or for loading the report from a DataTable.
Also, I would like to load an image in the header. I was able to put the image in through the designer, but I would like to do this in code because the image could change. How would I do this?
Thanks Again for your help.
-Matt-
I have made a report in the designer using a SQL Database Connection. This works well, but I actually need to manupulate some of the data in my application first.
My intention is to us the same SQL statement to get the data, edit some fields and then I would like to send the DataTable to the report to load rather than have it pull directly from the SQL Database.
How would I do this? I've found where I can pass the connection string and sql statement, but I haven't found any other options for passing anything else to the report or for loading the report from a DataTable.
Also, I would like to load an image in the header. I was able to put the image in through the designer, but I would like to do this in code because the image could change. How would I do this?
Thanks Again for your help.
-Matt-
Comments
and in frx file, add script (startreport event)
note: c# is a strong type language, therefore, datasource in your frx file must match with datatable :
<TableDataSource Name="MainReport" ReferenceName="MainReport" DataType="System.Int32" Enabled="true">
<Column Name="0" DataType="System.Int32"/>
<Column Name="1" DataType="System.DateTime"/>
<Column Name="2" DataType="System.String"/>
<Column Name="3" DataType="System.Int32"/>
<Column Name="4" DataType="System.Int32"/>
<Column Name="5" DataType="System.Decimal"/>
<Column Name="6" DataType="System.Decimal"/>
<Column Name="7" DataType="System.Decimal"/>
<Column Name="8" DataType="System.Decimal"/>
<Column Name="9" DataType="System.Decimal"/>
<Column Name="10" DataType="System.Decimal"/>
<Column Name="11" DataType="System.Decimal"/>
<Column Name="12" DataType="System.String"/>
</TableDataSource>
Is it alright that I connected my report to my SQL database so that I could drag and drop the fields? Or do I need to design the report differently as well?
Thanks so much!
Thank you so much, it never occurred to me that I would need to design the report during runtime as opposed to in the Fast-Reports Design Program. I will try that today.
Thank you very much for all of your help! This makes a lot more sense to me now.
I have been able to get everything working with the exception of the image.
In my demo project, I have it like so:
string fullpathname = @C:\Logo_Square.jpg;
// IF YOU WANT TO REUSE PREVIEWCONTROL1 FOR ANOTHER REPORT, DON'T FORGET THIS CODE
if (fastreportspreviewControl1.Report != null)
{
fastreportspreviewControl1.Clear();
fastreportspreviewControl1.Report.Dispose();
}
FastReport.Report report = new FastReport.Report();
//IF YOU WANT TO DESIGN A REPORT FOR THE VERY FIRST TIME, COMMENT THE CODE BELOW
//UNCOMMENT WHEN YOU FINISHED WITH REPORT DESIGNER
report.Load(@C:\Users\Matthew L\Desktop\Development Work\Reports\FastReports\PDInvoice.frx);
report.Preview = fastreportspreviewControl1;
report.SetParameterValue("FullPathNameOfPictureFile", fullpathname);
report.RegisterData(dt, dt.TableName);
//COMMENT WHEN YOU FINISHED WITH REPORT DESIGNER
//report.GetDataSource(dt.TableName).Enabled = true;
//report.Design(true);
//IF YOU WANT TO DESIGN A REPORT FOR THE VERY FIRST TIME, COMMENT THE CODE BELOW
//UNCOMMENT WHEN YOU FINISHED WITH REPORT DESIGNER
report.Prepare();
report.ShowPrepared();
In my report, I have a picturebox named Picture1 and the following in the Code tab:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;
namespace FastReport
{
public class ReportScript
{
private void StartReport(object sender, EventArgs e)
{
Picture1.ImageLocation = (String)Report.GetParameterValue("FullPathNameOfPictureFile");
}
}
}
Am I missing something? I am not getting an error of any kind, the picturebox just remains blank...
I'm very sorry to keep bothering you and wanted to thank you for all of your help.
Yes, I did add that Parameter and rename it to FullPathNameOfPictureFile.
I actually added a picturebox to my form and set it's image to the fullpathname and it does load in the pictureBox so I'm not sure why it wouldn't be loading in the report...
I was able to, as a work around, include the image file path as a column in my datatable and set the image in the report to this value and this did work. So I was able to get the image in there, just a different way. I don't know if this would be considered a bad method for any particular reason?
Thanks again for your help, I really appreciate it.
I have it working now, thank you very much for all of your help, I really appreciate it.
I am really impressed by Fast Reports. I have been playing around with a lot of other things while I was trying to get that working and can't believe how versatile and easy to use it is. This is an outstanding product!