在DataRow元素中更改Datetime对象的格式。

时间:2022-05-19 07:32:41

I have created a DataRow array: OBrienData from a data table build from a access database. I want to map its contents to another DataRow array NewClientData which will eventually be mapped to a mssql Database. PLease do not point out that there is other ways to map from Access to Mssql as i am doing this as an exercise. Everthing goes ok until i start mapping Datetime objects. I got an sql overflow error. When i looked i saw the format of the datetime object from access is different to what i required for the mssql database.

我已经创建了一个DataRow数组:从一个access数据库构建的数据表中的OBrienData。我希望将其内容映射到另一个DataRow数组NewClientData,该数据最终将映射到一个mssql数据库。请不要指出,有其他方法可以从访问Mssql映射到我作为一个练习。在我开始映射Datetime对象之前,一切都没问题。我有一个sql溢出错误。当我查看时,我看到datetime对象的格式与我在mssql数据库中所需要的不同。

string dateString,format="u";                                                                     
NewCaseData[i]["Date_Opened"] = DateTime.ParseExact(OBrienData[z]["Date opened"].ToString(), format,System.Globalization.CultureInfo.InvariantCulture);
NewCaseData[i]["Date_Closed"] = String.Format("{0:u}", OBrienData[z]["Date closed"]);

So i tried the above code. ParseExact gaves a error: 'string not valid' and string.format makes no change at all?!

所以我尝试了上面的代码。一个错误:“字符串无效”和字符串。格式根本没有变化?!

1 个解决方案

#1


0  

I was originally getting a sql overflow error. When i checked the data in the ms Database i found some of the data corrupted , null etc. So i used the try parse method in post : 7054782 to validate each value and copy over as normal or set to datetime.now or dbnull value.

我最初得到的是一个sql溢出错误。当我在ms数据库中检查数据时,我发现一些数据被破坏了,比如null等等。因此,我在post: 7054782中使用了try parse方法来验证每个值,并将其复制到正常或设置为datetime。现在还是dbnull价值。

#1


0  

I was originally getting a sql overflow error. When i checked the data in the ms Database i found some of the data corrupted , null etc. So i used the try parse method in post : 7054782 to validate each value and copy over as normal or set to datetime.now or dbnull value.

我最初得到的是一个sql溢出错误。当我在ms数据库中检查数据时,我发现一些数据被破坏了,比如null等等。因此,我在post: 7054782中使用了try parse方法来验证每个值,并将其复制到正常或设置为datetime。现在还是dbnull价值。