您好,欢迎来到佳博论文网!

计算机专业毕业设计:[56]c# string转datetime

天使将会展现网站编程最真实的一面,包括编程中遇到的一些错误指令的处理,网站调试过程,排查代码错误等,通过本系列经验,相信你在.net网站开发方面会有一个很大的提升。同时也希望小伙伴们喜欢天使的经验,把我的经验分享给更多需要帮助的人。

工具/原料

我们修改了时间之后发现,数据库中时间变为了:1900-01-01 00:00:00.000

将文本框中的string类型的值转换为时间类型

 DateTime New_time = DateTime.Parse(txtTime.Text);

        string ID = Request.QueryString["new_id"].ToString();        if (txtTitle.Text != "" || txtTime.Text != "" || txtAuthor.Text != "" || Content.Value != "")        {            DateTime New_time = DateTime.Parse(txtTime.Text);            string sql_change = "update news set new_title='" + txtTitle.Text + "',new_center='" + Content.Value + "',new_author='" + txtAuthor.Text + "',new_time='" + New_time + "' where new_id='" + ID + "'";            if (myclass.ExCom(sql_change))            {                Response.Write("<script>alert('文章:'+'" + txtTitle.Text + "'+' 修改成功!');location='user_center.aspx'</script>");            }        }

完善代码,当标题和作者等信息为空时,弹出消息框提示

            Response.Write("<script>alert('必填字段不能为空');location='user_center.aspx'</script>");            Page.Response.Redirect("new_edit.aspx?new_id=" + ID);

清空文章标题,点击【提交修改】

仍然出现这个提示,说明代码不严谨

修改判断条件,应该用“and”而不是或

if (txtTitle.Text != "" && txtTime.Text != "" && txtAuthor.Text != "" && Content.Value != "")