ormapper where clause failed for datetime datatype if UI and sqlserver has different culture

V

virendra.chandra

hi guys,
this is virendra.

I am in big trouble to handle date situation using where clause. i am
using ormapper.
if the sqlserver and application server has different date
format(different culture) then i am getting a error. datetime overflow.

How i can handle this situation.

ex:
DateTime _fromdate=new DateTime(2005,10,10);
DateTime _todate=DateTime.Now;
1.
string where= "CreateDate between '"+ _fromdate + "' and '" + _todate +
"'";

2.
string where= "CreateDate between '" +
DateTime.ParseExact(_fromdate.ToString(), "MM/dd/yyyy" ,
DateTimeFormatInfo.InvariantInfo)+ "' and '" +
DateTime.ParseExact(_todate.ToString(), "MM/dd/yyyy" ,
DateTimeFormatInfo.InvariantInfo) + "'";
 
F

Frans Bouma [C# MVP]

virendra.chandra said:
hi guys,
this is virendra.

I am in big trouble to handle date situation using where clause. i am
using ormapper.

which O/R mapper?
if the sqlserver and application server has different date
format(different culture) then i am getting a error. datetime
overflow.

How i can handle this situation.

ex:
DateTime _fromdate=new DateTime(2005,10,10);
DateTime _todate=DateTime.Now;
1.
string where= "CreateDate between '"+ _fromdate + "' and '" + _todate
+ "'";

2.
string where= "CreateDate between '" +
DateTime.ParseExact(_fromdate.ToString(), "MM/dd/yyyy" ,
DateTimeFormatInfo.InvariantInfo)+ "' and '" +
DateTime.ParseExact(_todate.ToString(), "MM/dd/yyyy" ,
DateTimeFormatInfo.InvariantInfo) + "'";

Doesn't your O/R mapper use parameterized queries?

FB




--
 
Top