Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying Crystal report in my application where i have to display records with select * from tblcart where uname=xyz query. but i am geting following error . can anyone help me.

Thank you

code:

String cn=System.Configuration.ConfigurationManager.ConnectionStrings["JBMConnectionString"].ToString();
SqlConnection con= new SqlConnection(cn);
SqlCommand command = new SqlCommand("Select * From tblcart where uname="+Session["uname"],con );
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
ReportDocument CustomerReport = new ReportDocument();
CustomerReport.Load(Server.MapPath("purchase.rpt"));

CustomerReport.SetDataSource(dataset.Tables[0]);
CrystalReportViewer1.ReportSource = CustomerReport;
CrystalReportViewer1.DataBind();




Error:

Server Error in '/JBM' Application.
Invalid column name 'b'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'b'.

Source Error:

Line 19: //Customer _Customer = new Customer();
Line 20: DataSet dataset = new DataSet();
Line 21: adapter.Fill(dataset);
Line 22: ReportDocument CustomerReport = new ReportDocument();
Line 23: CustomerReport.Load(Server.MapPath("purchase.rpt"));
Posted
Updated 14-Jan-13 18:20pm
v2

1 solution

Hi,

Try This.

C#
SqlCommand command = new SqlCommand("Select * From tblcart where uname='"+Session["uname"].ToString() +"' ",con );


Problem in your query may be missing single quote Or Session variable(object) conversion , Session variable(object) cannot convert automatic you have to convert it.

Thanks
Mark it as Ans if it resolve your query...
Asp.Net/C#.Net Help[^]
Hemant Singh
 
Share this answer
 
v2

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