Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Try to pass text box values to crystal report in asp.net.
but it will not fount parameter in my code. it will show popup parameter dialog box window to get value for crystal report.
Below is my Source code for parameter Passing :

C#
ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields();

ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@Name";
paramDiscreteValue.Value = TextBox1.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
reportDocument.Load(Server.MapPath("CrystalReport1.rpt"));

if (conn.State == ConnectionState.Open)
{
   conn.Close();
}

conn.Open();
string sql = "select * from CustomerDetails";
OdbcCommand cmd = new OdbcCommand(sql, conn);
OdbcDataAdapter dscmd = new OdbcDataAdapter(cmd);
DataTable datatable = new DataTable();
dscmd.Fill(datatable);
conn.Close();
reportDocument.SetDataSource(datatable);
CrystalReportViewer1.ReportSource = reportDocument;
Posted
Updated 19-May-15 3:05am
v2

1 solution

when passing values to a parameter in crystal report, I always use this code:

C#
reportDocument.SetDataSource(datatable);
reportDocument.SetParameterValue("Name", TextBox1.Text);
CrystalReportViewer1.ReportSource = reportDocument;
 
Share this answer
 
Comments
Member 10271164 20-May-15 8:52am    
Thanks Sir.
Dianne Ramos 20-May-15 19:46pm    
Im a Mam :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900