- C# code
行 24: cusInfo.CusPwd = txtPwd.Text;行 25: cusInfo.RightId = 1;行 26: cusInfo.Birthday =DateTime .Parse ( txtBirthday.Text);//此行出错行 27: cusInfo.Address = txtAddress.Text;行 28: cusInfo.Gender = ddlGender.SelectedValue;源文件: F:\毕业设计\webShop\WebShop\Register.aspx.cs 行: 26 堆栈跟踪: [FormatException: 该字符串未被识别为有效的 DateTime。] System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +2844238 System.DateTime.Parse(String s) +25 WebShop.Register.btnRegister_Click(Object sender, EventArgs e) in F:\毕业设计\webShop\WebShop\Register.aspx.cs:26 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
把出错行换成
cusInfo.Birthday = Convert.ToDateTime(txtBirthday.Text);
cusInfo.Birthday = Convert.ToDateTime(txtBirthday.Text.trim());
cusInfo.Birthday =DateTime.Parse(txtBirthday.Text.trim())也出现同样的错误,数据库中birthday为datetime类型
------解决方案--------------------------------------------------------
txtBirthday.Text的值不是一个格式正确的日期字符串,检查一下,确保其格式正确。
------解决方案--------------------------------------------------------
断点看看txtBirthday.Text是什么,能否为空,要么就做个异常处理
------解决方案--------------------------------------------------------
txtBirthday.Text.tostring("yyyy-mm-dd hh:mm:ss")
------解决方案--------------------------------------------------------