在我的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;
}
在該行的日期格式..? –
frmtxtdt.Text的值是什麼? –
這是什麼'DateTime日期= DateTime.Parse(DateTime.Today.ToShortDateString());'? 'DateTime.Today'實際上是'DateTime' – V4Vendetta