Incorrect syntax near ','.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using System.Globalization;
using System.Configuration;
namespace IT_Application
{
public partial class CryReport : System.Web.UI.Page
{
public string UserName;
SqlConnection con = new SqlConnection(@"Data Source=METHOUN;Initial Catalog=ITReportDb;Integrated Security=True");
ReportDocument crypt = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
DateTime strDate = Convert.ToDateTime(Request.QueryString["DateFrom"]);
DateTime endDate = Convert.ToDateTime(Request.QueryString["DateTo"]);
string txtUserName = Request.QueryString["UserName"];
GenerateReport(strDate,endDate);
}
protected void GenerateReport(DateTime strDate, DateTime endDate)
{
con.Open();
//SqlCommand cmd = new SqlCommand("SELECT * FROM tblReport WHERE Date between'" + strDate + "'and'" + endDate + "'", con);
SqlCommand cmd = new SqlCommand("SELECT * FROM tblReport WHERE Date between' " + strDate + "','" + endDate + "','"+UserName+" ' " , con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable datatable = new DataTable();
da.Fill(datatable); // getting value according to imageID and fill dataset
con.Close();
ReportDocument crystalReport = new ReportDocument(); // creating object of crystal report
crystalReport.Load(Server.MapPath("CrystalReport1.rpt")); // path of report
crystalReport.DataDefinition.FormulaFields["DateForm"].Text = "'" + strDate.ToString() + "'";
crystalReport.DataDefinition.FormulaFields["DateTo"].Text = "'" + endDate.ToString() + "'";
crystalReport.DataDefinition.FormulaFields["UserName"].Text = "'" + UserName.ToString() + "'";
crystalReport.SetDataSource(datatable); // binding datatable
CrystalReportViewer1.ReportSource = crystalReport;
}
}
}