我正在尝试将字符串转换为 DateTime,然后将其插入 sql。在我的本地计算机上一切正常,但在服务器上,应用程序抛出异常:
String was not recognized as a valid DateTime
我使用文本框来创建一个日期时间对象,如下所示:
我正在使用这条线来建立日期:
start = startEventTB.Text + " " + ShourDD.SelectedValue + ":" + SminuteDD.SelectedValue;
end = endEventTB.Text + " " + EhourDD.SelectedValue + ":" + EminuteDD.SelectedValue;
然后转换它
这是按钮单击后的代码:
act_event add_event = new act_event();
string start, end;
DateTime strt_date = new DateTime();
DateTime end_date = new DateTime();
add_event.name = name_event.Text;
start = startEventTB.Text + " " + ShourDD.SelectedValue + ":" + SminuteDD.SelectedValue;
end = endEventTB.Text + " " + EhourDD.SelectedValue + ":" + EminuteDD.SelectedValue;
strt_date = Convert.ToDateTime(start); //This is the line that throws the error
add_event.start = strt_date;
end_date = Convert.ToDateTime(end);
add_event.end = end_date;
add_event.description = des_event.Text;
add_event.address = loc_event.Text;
db.add_event(add_event);
然后我得到这个: