Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I am new in C#.
I fetch data from SQL and show it in a crystal report. After that I want to save that data which is shown in crystal report viewer. I have fetch data and show it in crystal report using Query. the coding is like this
con.Open();
string str = comboBox1.Text;
SqlCommand cmd = new SqlCommand("Select Emp_cod,projectId,projc_name,Description,StartDateOfProjct,EndDateOfProjct from Projct_Allocation where projectId=@id", con);
cmd.Parameters.Add(new SqlParameter("id", str));
SqlDataAdapter da = new SqlDataAdapter(cmd);
SqlCommandBuilder cmb = new SqlCommandBuilder(da);
DataSet2 ds = new DataSet2();
da.Fill(ds, "DataTable1");


CrystalReport2 ctr2 = new CrystalReport2();
ctr2.SetDataSource(ds);
crystalReportViewer1.ReportSource = ctr2;


This code run correctly. But after that I could not able to save data in Excel/PDF file which is shown in crystalReportViewer1.

I tried a lot but could not able to do this.
Please help me I would be very grateful to you.
Please!!!!!!!!!!!!!!!!!!!!!

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 18-Jun-11 21:41pm
v4
Comments
Smithers-Jones 18-Jun-11 11:42am    
Here is some cod: http://upload.wikimedia.org/wikipedia/commons/a/a3/Atlantic_cod.jpg

Reason for my vote of 1: Repost.
It's all fine saying "I tried a lot", but you didn't show, what you did.
thatraja 18-Jun-11 11:51am    
Smith, I have deleted other one.
Chris Maunder 18-Jun-11 13:23pm    
What have you tried?

As with all tasks, break it down into managable chunks, and do them one at a time. That way, the task doesn't seem so daunting.
What you are trying to do isn't difficult: something similar gets done every day. So if you put even a little bit of effort in, you can do it too.
Task: "fetch data from SQL and save it in Excel file"
Breakdown:
1) Get data from SQL.
1.1) Establish connection to SQL server
1.2) Get data from SQL in some form.

2) Save to excel file
2.1) Establish connection to Excel.
2.2) Send data to excel
2.3) Tell Excel to save data.

Each of those tasks is pretty easy (and has probably been covered in your course notes).
Try them, one by one, testing and making sure it works before moving on to the next.
 
Share this answer
 
Comments
Mithlesh Shaw 18-Jun-11 22:18pm    
Please offer me the codding
Now you have updated your question, here is the updated answer:
Google: A simple query took me here: C# Crystal Reports Export to Excel[^] which appears to include the source code. You didn't look that hard, did you? :laugh:
 
Share this answer
 
Comments
Tarun.K.S 19-Jun-11 6:24am    
This updated answer could have been included in your first answer using "Improve solution".
OriginalGriff 19-Jun-11 6:33am    
Yes, I know. But since he changed the question considerably I felt a new answer was more relevant.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900