0
嘗試插入一行數據時出現以下錯誤。它指出該字符串未被識別爲有效的日期時間。轉換爲日期時間時字符串未被識別爲有效日期時間
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'字符串? – Siyual
@Siyual EFTVFROM和EFTVTO變量 –
您可能需要使用'DateTime.ParseExact',但它確實取決於您期望得到的格式或格式。 – juharr