I have a form with a section for the user to enter his information and another persons information as well as a section to fill in a datagridview. Is it possible to transfer this information from the form to a crystal report on a button click so that it would look similar to the form without using a database exept maybe for the datagridview? |
| Zaider Tuesday, April 01, 2008 2:17 PM |
Hi,
You don't have to go via a database but crystal reports in visual studio can access datasets too.
When you create a connection to the "database" you can navigate to your project datasets.And since you can create datasets and tables of your own without relation to a real database you can use this functionality to your own avail.
Just make sure that the datasets are properly filled in before you show the report, set the datasource of the report and the information should show.
More advanced but also possible is to access the individual crystal objects like the textobjects and such. It is depending on the form sections which also show as objects. If this is what you are looking for I can dig up a simple example if you want. But if you have a lot of data to pass to the form you can do it in the above way more easily.
greetz,
Philip
|
| Philip_Stuyck__ Tuesday, April 01, 2008 2:39 PM |
Hi,
U r entering somevalues into ur textboxes rite??
So when u click the button, the value inthe text box should get added to datagrid and dataset
and then the report should be generated??? Am i right?
I created my crystal report project based on this step by step tutorial.
I followed all the steps exactly. Just look into this link.
http://www.aspfree.com/c/a/C-Sharp/Crystal-Reports-for-Visual-Studio-2005-in-CSharp/
|
| Viddhi Wednesday, April 02, 2008 4:51 PM |
Zaider,
In short, yes! but not being a Crystal Reports expert, will let someone else give you the details on how to achieve it.
Steve |
| яeverser Tuesday, April 01, 2008 2:39 PM |
Hi,
You don't have to go via a database but crystal reports in visual studio can access datasets too.
When you create a connection to the "database" you can navigate to your project datasets.And since you can create datasets and tables of your own without relation to a real database you can use this functionality to your own avail.
Just make sure that the datasets are properly filled in before you show the report, set the datasource of the report and the information should show.
More advanced but also possible is to access the individual crystal objects like the textobjects and such. It is depending on the form sections which also show as objects. If this is what you are looking for I can dig up a simple example if you want. But if you have a lot of data to pass to the form you can do it in the above way more easily.
greetz,
Philip
|
| Philip_Stuyck__ Tuesday, April 01, 2008 2:39 PM |
Hi,
This is my sample code wherein i have used arraylists as datasource. u can also give ur dataset here
Code Snippet
//User defined function which loads the crystal reports
// this is the sample report i created for stocks information
private void ConfigureCrystalReports() { string reportPath = Server.MapPath("StockObject.rpt");
StockObjectReport = new ReportDocument(); StockObjectReport.Load(reportPath); StockObjectReport.SetDataSource(StockValues); //stockvalues is my arraylist CrystalReportViewer.ReportSource = StockObjectReport;
}
|
| Viddhi Tuesday, April 01, 2008 3:46 PM |
Howwould you create a data set ordisplay an array properlyif the informationis comming from textbox's? |
| Zaider Tuesday, April 01, 2008 5:32 PM |
Zaider,
Perhaps build your array first? based on the values:
String[] values = new String[4];
values.SetValue(textBox1.Text, 0);
values.SetValue(textBox2.Text, 1);
values.SetValue(textBox3.Text, 2);
values.SetValue(textBox4.Text, 3); |
| яeverser Tuesday, April 01, 2008 5:35 PM |
Hi,
If u look into my project, i allow the users to enter the information and then store them in arraylists and then with them i create the crytal reports.
This link provides you to create crystal reports with datasets
http://www.codeproject.com/KB/cs/CreatingCrystalReports.aspx
http://www.beansoftware.com/ASP.NET-Tutorials/Using-Crystal-Reports.aspx
Code Snippet
//by default i am loading up some stock values
//Stock is my class
public void PopulateStockValuesArrayList() { if (Session["StockValues"] == null) { StockValues = new ArrayList(); Stock s1 = new Stock("YHOO", 25.45, 1000); Stock s2 = new Stock("GOOG", 234.56, 5000); Stock s3 = new Stock("MSFT", 45.80, 600); Stock s4 = new Stock("APPL", 89.7, 647); Stock s5 = new Stock("SUN", 67.99, 400); StockValues.Add(s1); StockValues.Add(s2); StockValues.Add(s3); StockValues.Add(s4); StockValues.Add(s5); Session["StockValues"] = StockValues; } else { StockValues = (ArrayList)Session["StockValues"];
}
}
//updating the arraylist withuser given information protected void btnaddStockInformation_Click(object sender, EventArgs e) { if (txtSymbol.Text != "" && txtPrice.Text != "" && txtVolume.Text != "") {
Stock temp = new Stock(); try { temp.Symbol = txtSymbol.Text; temp.Price = Convert.ToDouble(txtPrice.Text); temp.Volume = Convert.ToInt16(txtVolume.Text); } catch { } StockValues.Add(temp); Session["StockValues"] = StockValues; ConfigureCrystalReports(); txtSymbol.Text = ""; txtPrice.Text = ""; txtVolume.Text = ""; } else { }
|
| Viddhi Tuesday, April 01, 2008 6:22 PM |
I tried to create it like this for the datagridview by creating a dataset:
Code Snippet
OleDbDataAdapter oleDbDataAdapter = null;
DataSet ds = new DataSet();
OleDbCommand cmd = null;
OleDbConnection connectCmd = new OleDbConnection(dbConnect);
string sqlString3 = "Select * From QuoteDetail Where QuoteHeaderID = " + newOrderHeader;
cmd = new OleDbCommand(sqlString3, connectCmd);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
oleDbDataAdapter = new OleDbDataAdapter(cmd);
oleDbDataAdapter.Fill(ds);
cmd.Connection.Close();
CrystalReport2 myReport = new CrystalReport2();
myReport.SetDataSource(ds);
crystalReportViewer1.ReportSource = myReport;
Thinking I could just do the other textboxes by parameter but all I end up with is a blank report. |
| Zaider Wednesday, April 02, 2008 2:36 PM |
You have to actually create a crystal report first.
You can add one to your project via Project | Add new Item, and then select a crystal report.
Once there you can attach an existing crystal report source file, you know the files with rpt extension or create one from scratch.
If you create one from scratch, when you make a connection to a database you can choose to connect to your own project dataset instead of a real database. |
| Philip_Stuyck__ Wednesday, April 02, 2008 2:46 PM |
I've already added one to the form that's where crystalReport2 myReport = new CrystalReport(); is comming from. What I then need to be able to do is add my textboxes likelyby parameter and my datagridiew by dataset created on the button press like I was trying to do there. |
| Zaider Wednesday, April 02, 2008 2:57 PM |
Sorry i am not getting ur point..
Can u plz brief me once again?
|
| Viddhi Wednesday, April 02, 2008 3:53 PM |
Okay this is what I have so far done. I've added a crystal report to my project I have also added a crystal report viewer to a tab page on my form. What I want to do is be able to is add when a button is pressed the text boxes as parameters to the report and the datagridview as a data set. So I tried to do it like this so that the report is created once the button is pressed.
Code Snippet
OleDbDataAdapter oleDbDataAdapter = null;
DataSet ds = new DataSet();
OleDbCommand cmd = null;
OleDbConnection connectCmd = new OleDbConnection(dbConnect);
string sqlString3 = "Select * From QuoteDetail Where QuoteHeaderID = " + newOrderHeader;
cmd = new OleDbCommand(sqlString3, connectCmd);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
oleDbDataAdapter = new OleDbDataAdapter(cmd);
oleDbDataAdapter.Fill(ds);
cmd.Connection.Close();
CrystalReport2 myReport = new CrystalReport2();
myReport.SetDataSource(ds);
crystalReportViewer1.ReportSource = myReport;
It gives me a new report but it just shows up blank. |
| Zaider Wednesday, April 02, 2008 4:16 PM |
Hi,
U r entering somevalues into ur textboxes rite??
So when u click the button, the value inthe text box should get added to datagrid and dataset
and then the report should be generated??? Am i right?
I created my crystal report project based on this step by step tutorial.
I followed all the steps exactly. Just look into this link.
http://www.aspfree.com/c/a/C-Sharp/Crystal-Reports-for-Visual-Studio-2005-in-CSharp/
|
| Viddhi Wednesday, April 02, 2008 4:51 PM |
Thx for the link not doing a web app though which changes a few things and not all text box info is being put into the data grid view. |
| Zaider Wednesday, April 02, 2008 5:00 PM |
Hi,
As you are passing ur dataset to crystal reports, the dataset should be updated first.
Try to have two buttons as "Save info" or "Update dataset" which does the update functionality.
Try to get the text box information in an array or some object and update it to the dataset.
For example..
As u mentioned in the first post of this thread, user will be entering some of their personal information.
Lets consider two fields,
Age and email.
My best idea is to have a datatable and then add the datatable to the dataset.
From the query if u get user name, date of birth, bla bla etc, get that into datatable and add it to dataset.
And whatever fields u r getting from textbox , create a col name during run time and add the textbox values to it.
Now add the datatable to dataset and this wud be datadource to ur crystal report also to ur data grid.
hope i havent confused you!!!!
|
| Viddhi Wednesday, April 02, 2008 5:20 PM |
in the reporting section of the toolbox, you will find a reportdocument.
Drag one to the reportform for each report you want to support.
When dropping itto the form you will have to select the report you designed.
The reportdocument has to be assigned to the reportsource property.
I am usually doing this in the onload event of the form where the reportviewer is located:
Code Snippet
private void ReportForm_Load(object sender, EventArgs e)
{
switch (rapportName){
case "CRUren.rpt":
this.crystalReportViewer.ReportSource = this.crUren;
break;
case "CRAdapt.rpt":
this.crystalReportViewer.ReportSource = this.crAdapt;
break;
case "OverzichtTelefoonActiviteiten.rpt":
this.crystalReportViewer.ReportSource = this.overzichtTelefoonActiviteiten;
break;
case "TelefoniePerAflevernr.rpt":
this.crystalReportViewer.ReportSource = this.telefoniePerAflevernr;
break;
case "TelefoniePerAflevernrPerPostNr.rpt":
this.crystalReportViewer.ReportSource = this.telefoniePerAflevernrPerPostNr;
break;
}
}
In the above snipper I am supporting several reports, the reportname is filled in in the constructor of the form, it is just so I can use the same reportviewer for all my reports.
Then for every reportdocument there is an init event:
Code Snippet
private void crUren_InitReport(object sender, EventArgs e)
{
Trace.WriteLine("initreport uren");
if (dataSource != null)
{
crUren.SetDataSource(dataSource);
return;
}
}
In here I am adding my dataset as datasource and basically give it the data to work on. |
| Philip_Stuyck__ Wednesday, April 02, 2008 5:33 PM |