We have a windows base application and my client needs to work in Italian language too.When I change my regional settings to Italy and run the program I get the below error message.
“Cannot perform ‘=’ operation on System.DateTime and System.String.”
Can anyone help me on this?
The code is given below.
DataTable dt = new DataTable();
dt.Columns.Add("Date",Type.GetType("System.DateTime"));
TimeSpan t = new TimeSpan(1, 0, 0);
DateTime d = System.DateTime.Now;
for (int i = 0; i < 100; i++)
{
DataRow dr = dt.NewRow();
dr["Date"] = d.ToShortDateString();
dt.Rows.Add(dr);
d = d.AddDays(1.0);
}
DataRow[] dataRowArray = dt.Select("Date ="'8/31/2012'");
First, shouldn’t it be
dt.Select("Date ='8/31/2012'");? (Note that I removed a")Second, where is
"8/31/2012"coming from? It’s not a valid date in Italy, so you need to get that right("31/8/2012"), and then it should work.In other words, if it’s coming from a database, then you have to do a locale conversion before doing the comparison.