![](/img/trans.png)
[英]String was not recognized as a valid DateTime when converting to DateTime
[英]String not recognized as a valid DateTime when converting to datetime
嘗試插入一行數據時出現以下錯誤。 這說明該字符串未被識別為有效的日期時間。
C#
protected void saveExceptionAdd(object sender, System.EventArgs e)
{
//Default value secruity
if (ddlTimeFromAdd.SelectedIndex == 0 || ddlTimeToAdd.SelectedIndex == 0)
{
lblAddExcept.Visible = true;
lblAddExcept.Text = "Fields Required.";
divExceptionAdd.Focus();
}
else
{
string EFTVFROM = txtDatefromAdd.Text.ToString() + ddlTimeFromAdd.SelectedValue.ToString();
string EFTVTO = txtDatetoAdd.ToString() + ddlTimeToAdd.SelectedValue.ToString();
DateTime eftvfromdt = Convert.ToDateTime(EFTVFROM);
DateTime eftvtodt = Convert.ToDateTime(EFTVTO);
//Update WeekDay restriction
CDSSQLConnections.RunStoredProcedureWithNParams("connDataStore", "sp_AB_BULLETIN_EXCEPTION_INSERT",
new Dictionary<string, object> { { "EFTVFROM", eftvfromdt }, { "EFTVTO", eftvtodt }, { "ABSTATUS", ddlStatus.SelectedValue }, { "LASTMODBY", CDSSecurity.CurrentUserID } });
divExceptionAdd.Visible = false;
lblAddExcept.Visible = false;
repException.DataBind();
}
}
您可以告訴解析器應使用哪種日期時間格式來解析字符串
DateTime dt=DateTime.ParseExact("24/01/2013", "dd/MM/yyyy", CultureInfo.InvariantCulture);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.