Sivajihero Hero

Sivajihero Hero

  • NA
  • 105
  • 32.4k

Problem in displaying temporary column data in crystal repor

Jan 31 2016 2:41 AM
I have problem in displaying item in the crystal report. I need to display out put in crystal report. The code is given below. But the problem is, in my data table I have some branch names such as a1,a2,a3,a4. So if I type in TextBox1 value as a1 then in crystal report it will show value of a1 column, or if I type a2 then in crystal report it will show a2 column.
The desired output in crystal report may be like this if I type Textbox1 as a1
CODE   PRICE    brnch
N1        10.00       1
N2        15.00       2
How can I display this in crystal report. My code is given below.
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "a1";
DataTable dt1 = new DataTable();
String str1 = "select CODE,PRICE," + TextBox1.Text + " as brnch from brtable where " + TextBox1.Text + "!=0 ;";
SqlCommand xp1 = new SqlCommand(str1, con);
xp1.Parameters.Add("@search", SqlDbType.VarChar).Value = TextBox1.Text;
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter();
da1.SelectCommand = xp1;
da1.Fill(dt1);
con.Close();
if (dt1.Rows.Count > 0)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("stk.rpt"));
crystalReport.SetDatabaseLogon("xx", "xxxxxxx");
crystalReport.SetDataSource(dt1);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.DataBind();
}
}