Reputation: 67
I have crystal report, in which I need to get the value of textbox in crystal report. If I put textbox1= 1 then in crystal report it display as 1. How can I do this? This is my crystal report code in default.aspx page.
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "9";
TextBox2.Text = "02/02/2015";
TextBox3.Text = "02/03/2015";
DataTable dt = new DataTable();
String str = "select * from tbl1 where br=@search and Date between @search1 and @search2 ";
SqlCommand xp = new SqlCommand(str, con);
xp.Parameters.Add("@search", SqlDbType.VarChar).Value = TextBox1.Text;
xp.Parameters.Add("@search1", SqlDbType.VarChar).Value = TextBox2.Text;
xp.Parameters.Add("@search2", SqlDbType.VarChar).Value = TextBox3.Text;
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
crystalReport.SetDatabaseLogon("xx", "xxxx");
crystalReport.SetDataSource(dt);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.DataBind();
}
Here I need to display textbox1,2 and 3 value in crystal report
Upvotes: 1
Views: 1533
Reputation: 67
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "9";
DataTable dt = new DataTable();
String str = "select * from tbl1 where br=@search and Date between @search1 and @search2 ";
SqlCommand xp = new SqlCommand(str, con);
xp.Parameters.Add("@search", SqlDbType.VarChar).Value = TextBox1.Text;
xp.Parameters.Add("@search1", SqlDbType.VarChar).Value = TextBox2.Text;
xp.Parameters.Add("@search2", SqlDbType.VarChar).Value = TextBox3.Text;
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.SetParameterValue("search", "I am search");
crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
crystalReport.SetDatabaseLogon("xx", "xxxx");
crystalReport.SetDataSource(dt);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.DataBind();
}
}
I have added the parameter name as search.
but it shows error invalid report path. If I remove this line crystalReport.SetParameterValue("search", "I am search"); then its working.
Upvotes: 0
Reputation: 1784
At first you have to create 3 parameters in CrystalReport toolbox under Parameter Fields as shown in the following figure.
Then you need to pass the values from your behind code
var rpt=new ReportDocument();
rpt.SetParameterValue("Search1","I am search1");
rpt.SetParameterValue("Search2","I am search2");
rpt.SetParameterValue("Search3","I am search3");
CrystalReportViewer1.ReportSource = rpt;
Upvotes: 4