Asked by:
Parameter is not valid

Question
-
I am using this code for printing Crystal report with Button Click event its giving me this error while printing
Parameter is not valid.
this my code
protected void Button3_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); string query; con.Open(); query = "select * from Transactions where id='" + TextBox1.Text + "'"; cmd = new SqlCommand(query, con); cmd.Parameters.Add("@id", SqlDbType.Decimal).Value = TextBox1.Text; da = new SqlDataAdapter(cmd); dt.Clear(); da.Fill(dt); if (dt.Rows.Count > 0) { ReportDocument Report = new ReportDocument(); Report.Load(Server.MapPath("~/CrystalReport.rpt")); Report.SetDataSource(dt); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; Report.SetDatabaseLogon("sa", "123456789", @"server", "report"); CrystalReportViewer1.ReportSource = Report; CrystalReportViewer1.ReportSource = Report; CrystalReportViewer1.DataBind(); CrTables = Report.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } Report.Refresh(); Report.PrintToPrinter(1, true, 1, 1); } }
New born in developing
- Moved by Jason Dot Wang Thursday, November 29, 2012 5:48 AM This thread is about Crystal Report viewer (From:Visual C# Language)
Tuesday, November 27, 2012 12:03 PM
All replies
-
Which line gives the error? What are the values of all variables referenced on that line?
Paul Linton
Tuesday, November 27, 2012 12:07 PM -
Hi,
Add the below line of code
query = "select * from Transactions where id= @id";
PS.Shakeer Hussain
Tuesday, November 27, 2012 12:38 PM -
You create a paremeter that you never have passed in the query. Do as Syed already said, and it will work.
If you get your question answered, please come back and
Mark As Answer.
Web DeveloperTuesday, November 27, 2012 12:43 PM -
@Paul
Report.PrintToPrinter(1, true, 1, 1); this line gives the error
New born in developing
Wednesday, November 28, 2012 5:56 AM -
@Syed I tried like this but still the same error
New born in developing
Wednesday, November 28, 2012 5:57 AM -
To print all pages you would specify
Report.PrintToPrinter(1, true, 0, 0);
Have you checked if there are any pages in the report?
Paul Linton
Wednesday, November 28, 2012 6:00 AM -
Yes i tried with this line of code but same error
New born in developing
Wednesday, November 28, 2012 6:02 AM -
My previous post had three lines in it. Did you read the third line?
Paul Linton
Wednesday, November 28, 2012 6:04 AM -
the crystal report is Hidden i just want the print out of the crystal report .. its giving me this error when the report is Visible = false
when i try visible crystal report its giving me this errorMicrosoft JScript runtime error: 'Sys.Application' is null or not an objec
New born in developing
Wednesday, November 28, 2012 6:09 AM -
Was there a particular reason for keeping this information secret? You are asking people for help and then making their job as difficult as possible.
Paul Linton
Wednesday, November 28, 2012 6:12 AM -
no the website is deployed in IIS so its not displaying the report previously but printing the report . so i hide the report i keep only for printing , but now its giving me this type of error .
sorry for confusing u ,. :(
New born in developing
Wednesday, November 28, 2012 6:18 AM -
Where are the printer configuration configured before you print the document?
Report.PrintToPrinter(1, true, 1, 1);
SQL Error was valid but printer settings must be configured before calling the Print function.
Please mark it as an answer/helpful if you find it as useful. Thanks, Satya Prakash Jugran
Wednesday, November 28, 2012 6:25 AM -
Yes printer is configured before printing the document . same code is working in one application .. which is not deployed yet ..
but in this its giving error..
New born in developing
Wednesday, November 28, 2012 6:33 AM -
Hi Mohammed Abdul Muqeet,
Welcome to MSDN Forum Support.
You'll need to post it in the dedicated Crystal Report viewer Forum http://forums.sdn.sap.com/forum.jspa?forumID=313 for more efficient responses, where you can contact Crystal Report viewer experts.
Hope it helps you.
Sincerely,
Jason WangJason Wang [MSFT]
MSDN Community Support | Feedback to us
Thursday, November 29, 2012 5:47 AM