Last post Oct 18, 2016 07:04 PM by codemovement.pk
Oct 17, 2016 09:45 AM|acmedeepak|LINK
I was asked to create invoice reports using C#, ASP.NET. My client restricts me to use crystal reports. Please do let me know what I can do. Can I create reports using C# code or do we have any other options? My reports need to be in a tabular format and
the paper size is 8.5 by 11. can anyone pass me a code on how to do this.
Please help me in achieving this.
Oct 17, 2016 02:49 PM|codemovement.pk|LINK
Yes, you can still do it in crystal report. You just need to create a data source and pass it to crystal report. All are drag and drop thing.
I am sending you sample code I hope you can achieve it by using this.
protected void Page_Load(object sender, EventArgs e)
ReportDocument rptDoc = new ReportDocument();
dsSample ds = new dsSample(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Crystal Report Example";
dt = getAllOrders(); //This function is located below this function
// Your .rpt file path will be below
//set dataset to the report viewer.
CrystalReportViewer1.ReportSource = rptDoc;
public DataTable getAllOrders()
//Connection string replace 'databaseservername' with your db server name
string sqlCon = "User ID=sa;PWD=sa; server=databaseservername;INITIAL CATALOG=SampleDB;" +
"PERSISTSECURITY INFO=FALSE;Connect Timeout=0";
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
//Stored procedure calling. It is already in sample db.
cmd.CommandText = "getAllOrders";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Con;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
catch (Exception ex)
throw new Exception(ex.Message);
if (Con.State != ConnectionState.Closed)
Oct 17, 2016 05:45 PM|acmedeepak|LINK
As I have already mentioned, I do not have permissions to use Crystal Reports. It could be SSRS or any other report service. It is preferable if the report is generated via C# code by retrieving values from data base. So, I am still looking for an answer
but your code is good. Thanks for your help. I really appreciate that.
Oct 17, 2016 05:51 PM|ryanbesko|LINK
As I have already mentioned, I do not have permissions to use Crystal Reports.
"My client restricts me to use crystal reports."
Oct 17, 2016 06:44 PM|acmedeepak|LINK
In both the cases, I can not use crystal reports. So, Need to look for another option. Please help me...
I am seeking a solution for my problem.
Oct 17, 2016 06:54 PM|mgebhard|LINK
If you can use SSRS then why don't you use SSRS? There are plenty of online tutorials that explain how to create an SSRS report.
You might also find the Report Viewer helpful.
Oct 18, 2016 02:13 PM|codemovement.pk|LINK
Your question mislead me. Well, there is an option that you can utilize SSRS services of SQL server for report creation but again its an expensive procedure as you need reporting server too.
I am giving you some basic article for SSRS report creation.
Above link is a step by step guide of report creation along with a code, in case of any query in above link code do let me know.
Hope it helps.
Oct 18, 2016 02:23 PM|senthilwaits|LINK
Try this. You can use RDLC without SSRS
Oct 18, 2016 06:51 PM|acmedeepak|LINK
Thanks for the code codemovement.pk.
I really appreciate your coming back for my query. I will look into the link you have provided and work on the same. Is there any possibility to create reports using only the C# code. That would help me a lot.
Thanks for all your help and suggestions everyone,
Oct 18, 2016 07:04 PM|codemovement.pk|LINK
Yes there is a way you can make your own custom report. You can achieve this in the following way.
1- Create(Design) a dynamic HTML template or XML that fulfill your report purpose.
2- Fill the data in the HTML.
3- On report generation button click convert HTML template or XML template to PDF by using Itext sharp library(open source).
4- Print PDF.
In this way you can generate fully customized report.
Above mentioned link may help you allot to generate report using C#.
Hope suggested solution will help.