I have a view called DailyVisitSummary
. If I select FromDate
and ToDate
, it will generate the report called rpt.VisitSummaryReport
depending upon the selected dates.
I am using Crystal Reports to generate reports. If I run my application (on my local machine), the report is working fine. But if I check my application after deploying to a local host using IIS Server, the report is not working correctly. It is showing an error. The error which is mentioned in the below image (second one)
My VisitorsViewModel
;:
public DateTime ? FromDate { get; set; }
public DateTime ? ToDate { get; set; }
My view:
<div class="form-group">
@Html.LabelFor(model => model.FromDate)
@Html.TextBoxFor(model => model.FromDate, new { @class = "form-control", type = "text" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.ToDate)
@Html.TextBoxFor(model => model.ToDate, new { @class = "form-control", type = "text" })
</div>
My jQuery code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script>
$("#FromDate").datepicker({
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true,
});
$("#ToDate").datepicker({
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true,
});</script>
My controller code:
public ActionResult VisitSummaryReport()
{
return View();
}
[HttpPost]
public ActionResult GetDates(VisitorsViewModel VisitorsVM)
{
var fromdt = Convert.ToDateTime(VisitorsVM.FromDate);
var todt = Convert.ToDateTime(VisitorsVM.ToDate);
SqlConnection con = new SqlConnection(@"Data Source=192.168.0.73\SQLEXPRESS,14330;Initial Catalog=WafeERP_NEW;User ID=sa;Password=wafewin;");
DataTable dt = new DataTable();
try
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from View_VisitorsForm where VisitingDate >='" + fromdt +"'and VisitingDate <= '" + todt +"'", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
catch (Exception ex)
{
throw;
}
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("~/Areas/Sales/CrystalReports/rpt_VisitSummaryCrystalReport.rpt"));
rpt.SetDataSource(dt);
Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
I tried my level best to explain my issue. Any one understand my issue and help me to resolve this issue.
Thanks in advance.