在我的 Web 项目中,我正在解析在日期选择器中选择的日期,并将其与从数据库中获取的日期进行比较,直到昨天它工作正常,但从今天早上开始它会抛出格式异常,这可能是问题所在,
我的代码是,
try
{
ReportDocument rpt = new ReportDocument();
DateTime dt = DateTime.Parse(frmtxtdt.Text); // Exception Thrown here
DateTime dt1 = DateTime.Parse(frmtxtdt.Text);
DateTime date = DateTime.Parse(DateTime.Today.ToShortDateString());
DateTime date1 = DateTime.Parse(DateTime.Today.ToShortDateString());
string frtxt = String.Format("{0:MM-dd-yyyy}", dt);
string totxt = String.Format("{0:MM-dd-yyyy}", dt1);
DataSet ds = Namespace.SP.Storedprocedure(frtxt,totxt).GetDataSet();
if (!IsPageRefresh)
{
if (ds.Tables[0].Rows.Count > 0)
{
if(frtxt == ds.Tables[0].Rows[0]["Date"].ToString()
&& totxt == ds.Tables[0].Rows[0]["Date"].ToString())
{
ds.Tables[0].TableName = "Passkeys";
ds.WriteXml(Server.MapPath("~/XML/Passkeys.xml"));
string filename = Server.MapPath("~/Upload/Pkey_rpt.rpt");
rpt.Load(filename);
rpt.SetDataSource(ds);
rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Passkeys - " + ds.Tables[0].Rows[0]["Date"].ToString());
}
}
else if(frmtxtdt.Text.Trim() !=null && totxtdt.Text.Trim()!=null)
{
if (frtxt == String.Format("{0:dd-MM-yyyy}", date)
&& totxt == String.Format("{0:dd-MM-yyyy}", date1)
&& ds.Tables[0].Rows.Count == 0)
{
ClientMessaging( "Pass Key(s) Not Yet Delivered for the Selected Date...");
}
else
{
ClientMessaging( "There is No Schedule for the Selected date....");
}
}
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message;
}