to pass textbox value to crystal report
-
Friday, September 18, 2009 8:06 AMhi!i have a form called "dailyreport" .In this form i have a textbox and a button.Textbox will get a date value from user and then user have to click the button to view crystal report.My crystal report shows patient's name and id who visited the clinic on that particular date ( textbox value).now i have the requiremtent in which i have to show this date(ie, textbox value) on the crystal report..So, how can i pass this textbox.text value to my crystal report???pls provide some solution!!
nandini
All Replies
-
Friday, September 18, 2009 10:08 AM
Hi Nandini,
I didn't understand your problem.
You are getting the patients details who visited the clinic on that particular date means you are passing the date to crystal report... then what is the problem....
If you are using dataset to retrieve the data... use like this
Select tdate, patientid, patientname, otherdetails from patients where tdate='12/12/09'
you will get date with this data.... use the same date in your crystal report
if this is not your problem
Here is the way to access the textboxes present in different Sections of Crystal Report Object
Here TXTCNAME is the name of textbox present in Sections(0) of Crystal ReportDim RptForm As CrystalDecisions.CrystalReports.Engine.ReportDocument Dim T As CrystalDecisions.CrystalReports.Engine.TextObject RptForm = New MyCrystalReport() T = RptForm.ReportDefinition.Sections(0).ReportObjects("TXTCNAME") T.Text = DTPTDate.Value
MyCrystalReport is the crystal Report you want to use.
After initializing the crystal report use these Statements.
Sharp Eyes- Marked As Answer by NandiniP Friday, September 18, 2009 11:43 AM
-
Friday, September 18, 2009 10:22 AMhi!!thanks for your reply!!no, i don't have "date" as the data in the crystal report. i jst have patient name and id in the crystal report's database field.i am filtering my data to be shown on crystal report using the date value which user will enter in the form.i need to show this date on the crystal report..which means i have to pass it as parameters field.but after this, i don't know how to proceed..
nandini -
Friday, September 18, 2009 10:35 AMHi Nandini,
Then you can use the second procedure I have given....
or
use the same parameter field to display the date.
Sharp Eyes -
Friday, September 18, 2009 10:39 AMthanks again for your reply..
but my textbox( for date) is not present on section(0) of crystal report..infact it is on some other windows form and from this form i need to pass this value to crystal report using c# language.
nandini -
Friday, September 18, 2009 10:50 AM
I didn't understand your problem....
1. Do you want to know how to pass a parameter to the crystal report?
2. Where exactly you want to place that date value in your report. In which section it is available. What is the name of the textbox object in that section.
3. Is your daily report working perfectly... is it displaying the data of patients who visited the clinic on the specifed date? OR it is displaying all the patients data
Give me your table structure and some code you have written ... so that I can understand it.
Sharp Eyes -
Friday, September 18, 2009 11:06 AM
1) yes, i want to know how to pass a paramtere to the crystal report2) i have taken a parameter field named "?date" and i want to put it in the page header section of the crystal report..and in this filed i need to show the date.3) and yes my daily report working fine..i.e., it showing me the table which contains patient data.i jst need to do one more thing that is to show that particular date on crystal report for which the user has retrieved the data.SqlDataAdapter adp = new SqlDataAdapter("select pName,gicNo from patient where date="txtdate.Text, con); DataSet dev = new dailyReportDS(); DataSet ds = new DataSet(); adp.Fill(ds); dev.Tables[0].Merge(ds.Tables[0]); CRDailyVisitingPatientRecord rpt = new CRDailyVisitingPatientRecord(); rpt.SetDataSource(dev.Tables[0]); crystalReportViewer1.DisplayGroupTree = false; crystalReportViewer1.ReportSource = rpt;above data is showing my other requiremtnts.thanks!!
nandini -
Friday, September 18, 2009 11:22 AM
Then the answer is in the first reply itself....
header section means sections(0)
In header section to display the date value ... i think you have kept a textbox object in your crystal report... note down the name of that textbox object...
use the following code...
SqlDataAdapter adp = new SqlDataAdapter("select pName,gicNo from patient where date="txtdate.Text, con);
DataSet dev = new dailyReportDS();
DataSet ds = new DataSet();
adp.Fill(ds);
dev.Tables[0].Merge(ds.Tables[0]);
CRDailyVisitingPatientRecord rpt = new CRDailyVisitingPatientRecord();
''''my code starts here (coding in VB.NET... convert it to C#)
Dim RptForm As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim T As CrystalDecisions.CrystalReports.Engine.TextObject
RptForm = rpt; 'rpt is your report object
T = RptForm.ReportDefinition.Sections(0).ReportObjects("t2") ''''here my assumption is t2 is the textbox name in which you want to display the date
in your crystal report
T.Text = txtdate.text '''' this will display the date value in the textbox .... txtdate is the textbox in your form for user input
''''my code ends here
rpt.SetDataSource(dev.Tables[0]);
crystalReportViewer1.DisplayGroupTree = false;
crystalReportViewer1.ReportSource = rpt;
Sharp Eyes- Marked As Answer by NandiniP Friday, September 18, 2009 11:44 AM
-
Friday, September 18, 2009 11:35 AM
hi!i have done something like this..CrystalDecisions.CrystalReports.Engine.ReportDocument RptForm; CrystalDecisions.CrystalReports.Engine.TextObject txtobj; RptForm = rpt; txtobj = RptForm.ReportDefinition.Sections[0.ReportObjects["txtDate"]; txtobj.Text = tbDate.Text.ToString();but i am getting the following error in the following linetxtobj = RptForm.ReportDefinition.Sections(0).ReportObjects("txtDate");Non-invocable member 'CrystalDecisions.CrystalReports.Engine.ReportDefinition.Sections' cannot be used like a method.
nandini- Edited by NandiniP Friday, September 18, 2009 11:43 AM
-
Friday, September 18, 2009 11:39 AMSections is a collection object there or array
You have to use Sections[0] ............. I don't know the C# syntax ....
try this
txtobj = RptForm.ReportDefinition.Sections[0].ReportObjects["txtDate"]
Sharp Eyes -
Friday, September 18, 2009 11:43 AMhi!!
ya that was completely my mistake :)but thanks a lot!!you have solved my problem..thanks a ton!!
nandini -
Tuesday, September 29, 2009 7:08 AM
Hi Nandini,
can the above code work in vb code kindly?
I didn't understand your problem.
You are getting the patients details who visited the clinic on that particular date means you are passing the date to crystal report... then what is the problem....
If you are using dataset to retrieve the data... use like this
Select tdate, patientid, patientname, otherdetails from patients where tdate='12/12/09'
you will get date with this data.... use the same date in your crystal report
if this is not your problem
Here is the way to access the textboxes present in different Sections of Crystal Report Object
Here TXTCNAME is the name of textbox present in Sections(0) of Crystal ReportDim RptForm As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim T As CrystalDecisions.CrystalReports.Engine.TextObject
RptForm = New MyCrystalReport()
T = RptForm.ReportDefinition.Sections(0).ReportObjects("TXTCNAME")
T.Text = DTPTDate.Value
MyCrystalReport is the crystal Report you want to use.
After initializing the crystal report use these Statements.
Sharp Eyes -
Tuesday, September 29, 2009 7:45 AMHi mwashke,
Its VB Code... it will work in VB.net
Sharp Eyes -
Saturday, November 21, 2009 8:07 AMThank you I had this problem was solved http://www.akairan.com :)
-
Monday, March 28, 2011 5:07 PM
Hi Nandhini,
i was doing the same wat you are doing but am getting the error message as "Cannot implicitly convert type 'CrystalDecisions.CrystalReports.Engine.ReportObject' to 'CrystalDecisions.CrystalReports.Engine.TextObject'. An explicit conversion exists"
Below is my code :
CrystalReport1 rpt_doc = new CrystalReport1();
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt_form;
CrystalDecisions.CrystalReports.Engine.TextObject T;
rpt_form = rpt_doc;
T = rpt_form.ReportDefinition.Sections[0].ReportObjects["Billno"];
T.Text = Txt_Billno.Text.ToString();
crystalReportViewer1.ReportSource = rpt_doc;Thanks in advance....

