Skip to content

Commit 1620455

Browse files
author
mikhaild908@gmail.com
committed
fixed a runtime error that happens when the format of the date is not the same as the current culture’s date format - added entry to IBatisNet.DataMapper.Test.dll.config called dateTimeFormat
1 parent e9b07e2 commit 1620455

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<!-- To test via Odbc provider (any database) value="Odbc" -->
2929
<!-- To test via SQLIte 3 value=SQLite3 -->
3030
<add key="providerType" value="SQLClient"/>
31+
<add key="dateTimeFormat" value="yyyy-MM-dd H:mm:ss" />
3132
</appSettings>
3233

3334
<iBATIS>

src/IBatisNet.DataMapper/Commands/DataReaderDecorator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using System;
2727
using System.Data;
2828
using IBatisNet.DataMapper.Scope;
29+
using System.Configuration;
30+
using System.Globalization;
2931

3032
namespace IBatisNet.DataMapper.Commands
3133
{
@@ -248,6 +250,13 @@ string IDataRecord.GetDataTypeName(int i)
248250
/// <exception cref="System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"></see>. </exception>
249251
DateTime IDataRecord.GetDateTime(int i)
250252
{
253+
string dateTimeFormat = ConfigurationManager.AppSettings["dateTimeFormat"];
254+
255+
if (!string.IsNullOrWhiteSpace(dateTimeFormat))
256+
{
257+
return DateTime.ParseExact(_innerDataReader.GetString(i), dateTimeFormat, CultureInfo.InvariantCulture);
258+
}
259+
251260
return _innerDataReader.GetDateTime(i);
252261
}
253262

0 commit comments

Comments
 (0)