My problem is that I have to send my textbox data to crystal report, i am trying a lot but iam not getting I know how to use crystal though database.
Thanks

Dani AI

Generated

asked how to pass TextBox data into a Crystal Report, and linked to an MSDN thread that may be inaccessible. Below is a compact, reliable pattern for ASP.NET (VB.NET) that covers the two common approaches (report parameter vs. selection formula) and the typical pitfalls to watch for.

Recommended approaches:

  • Add a ParameterField to the .rpt (for example SearchParam) and set it from code with SetParameterValue. This is the cleanest way to pass a single value.
  • If the report is not DB-bound, build a DataTable/DataSet in code, fill it with the TextBox value, and call ReportDocument.SetDataSource(myDataSet).
  • To filter database-backed reports server-side, set the report selection formula via DataDefinition.RecordSelectionFormula (avoid client-side filtering).

Example (VB.NET):

Protected Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
    Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
    rpt.Load(Server.MapPath("~/Reports/MyReport.rpt"))

    ' Option A: pass textbox value to a report parameter named "SearchParam"
    rpt.SetParameterValue("SearchParam", TextBox1.Text)

    ' Option B: filter DB records directly (uncomment to use)
    ' rpt.DataDefinition.RecordSelectionFormula = "{Customers.Name} = '" & TextBox1.Text.Replace("'", "''") & "'"

    CrystalReportViewer1.ReportSource = rpt
    CrystalReportViewer1.DataBind()
End Sub

Troubleshooting notes:

  • Parameter name must match the .rpt parameter exactly. Save the .rpt after adding the parameter.
  • If the .rpt connects to a DB, set table logon credentials programmatically or use integrated security; otherwise the report may show no data.
  • Escape quotes when building selection formulas and prefer parameters when possible.
  • Dispose reports on unload (rpt.Close(); rpt.Dispose()) or keep one ReportDocument per session to avoid memory leaks.

Recommended Answers

All 3 Replies

this site is not opening ..................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.