我在交易日期后有一个时间点。 因此,我从C#.net前,以以下格式通过:
2011-01-01 12:17:51.967
我写道:
介绍层:
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
PropertyClass prp=new PropertyClass();
Prp.TransDate=Convert.ToDateTime(date);
财产 班级结构:
Public class property
{
private DateTime transdate;
public DateTime TransDate
{
get
{
return transdate;
}
set
{
transdate = value;
}
}
}
从DAL层穿过“交易”这样的交易:
Cmd.Parameters.AddWithValue("@TranSactionDate”, SqlDbType.DateTime).value=propertyobj.TransDate;
草原层的分解:
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
我正在获得正确的预期日期格式,但当辩论转向这一行文时。
Prp.TransDate=Convert.ToDateTime(date);
日期改为2011年1月1日。
But my backend sql datefield wants the date paramter 2011-01-01 12:17:51.967 in this format otherwise throwing exception invalid date format.
www.un.org/Depts/DGACM/index_spanish.htm 注:虽然时间过长,但并未将例外情形改为:
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value) at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value) at System.Data.SqlTypes.SqlDateTime..ctor(DateTime value) at System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb) at System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)