Click here to Skip to main content
11,576,060 members (57,714 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 14-Jan-13 18:17pm
Edited 14-Jan-13 18:20pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Try This.

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
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 305
1 F-ES Sitecore 145
2 OriginalGriff 125
3 Abhinav S 98
4 Dave Kreskowiak 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100