我取字符串变量列表日期项,然后我想将它插入SQL表中,但在SQL列类型是日期时间。所以我需要将字符串转换为DateTime。日期时间在SharePoint 2007
我使用下面的代码:
DateTime strAllocatedOn;
string[] format = { "dd/MM/yyyy HH:mm:ss tt", "dd-MM-yyyy HH:mm:ss tt" };
DateTime.TryParseExact(dt.Rows[j]["Created"].ToString(), format, null, DateTimeStyles.None, out strAllocatedOn);
但是,得到如下错误:
这我recevingAn error occurred during the compilation of the requested file, or one of its dependencies. Invalid expression term 'out'
日期格式为 “10/3/2011下午4时38分27秒”。
当心,因为DateTime格式可以根据用户的区域设置改变。但看着代码,我觉得你做的事情不正确。 'dt.Rows [j]'是否真的返回一个字符串或DateTime? dt.Rows [j] .GetType()返回什么? – 2012-01-05 10:38:13
嗨感谢您的答复.. 是的,它是retunring我检查它的日期。 – AndroidGuy 2012-01-05 11:31:24
这是一个编译错误说,它得到了一个“出”的表达,当它没有意义。你上面粘贴的代码看起来很好。你确定它不是导致错误的代码的另一部分吗? – 2012-01-05 12:32:11