I use ADO disconnected mode to get data from database by filling dataset ds. All data come true except the date field
string strDate = ds.Tables[0].Rows[0]["H_DT"].ToString();
it throws an exception says:
Specified time is not supported in this calendar. It should be between 04/30/1900 00:00:00 (Gregorian date) and 11/16/2077 23:59:59 (Gregorian date), inclusive.
I tried to write this code
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-sa");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-sa");
to change the culture to Arabic but without any luck.
Update
The following is screenshot of quick watch for the variable

From
DateTime.ToStringmethodYour
ar-saculture's default calender isUmAlQuraCalendarcalender.And from
UmAlQuraCalendar.MinSupportedDateTimePropertySince your
DateTimeis1, 1, 1398, it is too normal to throwsArgumentOutOfRangeException.You can solve your problem to provide parameter an
IFormatProviderin yourDateTime.ToString()method which hasGregorianCalendarby default. You can useInvariantCulturefor example.A
DateTimebelongs on Gregorian calendar by default. FromDateTimestructure;That means your
ds.Tables[0].Rows[0]["H_DT"]datetime is Gregorian calender by default. But since you using.ToString()method without any parameter, your method uses yourCurrentCulturewhich isar-sasince you wrote it in your web.config. And that culture hasUmAlQuraCalendarcalender by default. Since your datetime out of range in this calender, your code throws exception.Remember, you have a
DateTimewith1318as a year in Gregorian calender, not1318as a year inUmAlQuraCalendarcalender.As an example;
throws
ArgumentOutOfRangeExceptionexception because it is exactly the same case of yours. This is a DateTime which is a1318year in a Gregorian calender, but there is no representation onUmAlQuraCalendarcalender of this datetime because inUmAlQuraCalendarcalender, years start with1900in Gregorian calender.Take a look at how
UmAlQuraCalendarcalender implemented;