Ashwin_shastry
asked on
crystal report using stored procedure
Hi:
I want to generate a report b/w some time...I am using stored procedure for that...But i m not getting the desired result.Here is my code
SqlConnection sqlConnection = new SqlConnection(Configuratio nSettings. AppSetting s["Connect ionString" ]);
SqlCommand sqlCommand = new SqlCommand("gal_report_per sonnel", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedur e;
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlAdapter.SelectCommand = sqlCommand;
DataSet ds = new DataSet();
sqlCommand.Parameters.Add( "@Effectiv eDate1",Sq lDbType.Sm allDateTim e,4);
sqlCommand.Parameters["@Ef fectiveDat e1"].Value ="1/1/2005 ";
sqlCommand.Parameters.Add( "@Effectiv eDate2",Sq lDbType.Sm allDateTim e,4);
sqlCommand.Parameters["@Ef fectiveDat e2"].Value ="2/1/2005 ";
sqlAdapter.Fill(ds,"USER DATA");
creport.SetDataSource(ds);
CrystalReportViewer1.Repor tSource = creport;
CrystalReportViewer1.DataB ind();
I am bind the dataset using SetDataSource(ds).But when i run the report I see all the values....but it should show me just 6 results but its showing everything. Where am i doing wrong...
Pls help me.
Thanks
Ashwin
I want to generate a report b/w some time...I am using stored procedure for that...But i m not getting the desired result.Here is my code
SqlConnection sqlConnection = new SqlConnection(Configuratio
SqlCommand sqlCommand = new SqlCommand("gal_report_per
sqlCommand.CommandType = CommandType.StoredProcedur
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlAdapter.SelectCommand = sqlCommand;
DataSet ds = new DataSet();
sqlCommand.Parameters.Add(
sqlCommand.Parameters["@Ef
sqlCommand.Parameters.Add(
sqlCommand.Parameters["@Ef
sqlAdapter.Fill(ds,"USER DATA");
creport.SetDataSource(ds);
CrystalReportViewer1.Repor
CrystalReportViewer1.DataB
I am bind the dataset using SetDataSource(ds).But when i run the report I see all the values....but it should show me just 6 results but its showing everything. Where am i doing wrong...
Pls help me.
Thanks
Ashwin
Shouldn't the parameters be added before this line?
sqlAdapter.SelectCommand = sqlCommand;
The adapter command doesn't have the parameters.
mlmcc
sqlAdapter.SelectCommand = sqlCommand;
The adapter command doesn't have the parameters.
mlmcc
ASKER
BriCrowe:
I want the records between 1/1/2005 and 2/1/2005. Those are Effective date 1 and 2. For right now i have hard coded.
I want the records between 1/1/2005 and 2/1/2005. Those are Effective date 1 and 2. For right now i have hard coded.
ASKER
Also I tried displaying those values by giving the datasource as datagrid....It Displayed all the values b/w 1/1/2005 and 2/1/2005.
I asked about the parameters because I was thinking as mlmcc indicated that the parameters applied to sqlcommand may not carry to the selectcommand.
ASKER
Since the values I wanted are in the dataset...I m wondering am i making wrong in giving the datasource to the crystalreport....? I mean
creport.SetDataSource(ds);
CrystalReportViewer1.Repor tSource = creport;
CrystalReportViewer1.DataB ind();
How about this code...?
creport.SetDataSource(ds);
CrystalReportViewer1.Repor
CrystalReportViewer1.DataB
How about this code...?
Does the report have saved data?
mlmcc
mlmcc
ASKER
i dont know what is saved data....pls help me to solve this...
ASKER
Please help me to solve this errorrrrrrr......I m ready to give even 500 points...If my error gets solved today.
Thanks
Thanks
I'm curious why you are setting the datasource of the crystal report from your code. Doesn't the report have its own datasource defined. I don't know if this is the problem but I use stored procedures for several of my reports and display them in a vb.net app and all i have to do is load the .rpt file, establish the connection, set the parameter values, and set the crystalreportviewer source
private m_crReport as new reportdocument
...
m_crReport.Load("PriceShee t.rpt")
(define connection info)
...
m_crReport.SetParameterVal ue("@SLPri ceGroup", cboSLPriceGroup.Text)
m_crReport.SetParameterVal ue("@IGPri ceGroup", cboIGPriceGroup.Text)
m_crReport.SetParameterVal ue("@Custo merID", Nothing)
m_crReport.SetParameterVal ue("@Custo merName", String.Empty)
crvPricesheet.ReportSource = m_crReport
private m_crReport as new reportdocument
...
m_crReport.Load("PriceShee
(define connection info)
...
m_crReport.SetParameterVal
m_crReport.SetParameterVal
m_crReport.SetParameterVal
m_crReport.SetParameterVal
crvPricesheet.ReportSource
Saved Data
Open the report
Click FILE
Ensure SAVE DATA WITH REPORT is not checked.
mlmcc
Open the report
Click FILE
Ensure SAVE DATA WITH REPORT is not checked.
mlmcc
ASKER
I could fix the problem....The error was due was due to authentication of database. I used to connect to database for report from my local server and the values i was getting from stored procedure was from production server. To work fine...I should be using the local server for both or production server.
The mistake was i used localserver for reports and to fill dataset i was using production server. Finally could resolve this....by using local server for both.
Thanks for everyone for answering my question.
The mistake was i used localserver for reports and to fill dataset i was using production server. Finally could resolve this....by using local server for both.
Thanks for everyone for answering my question.
PAQ/Refund
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
sqladapter.selectcommand.p
and
sqladapter.selectcommand.p
right before the fill?