1

I'm using C# and I have a strange problem: when I retrieve the date from MySQL and converting it to a string using ToString(), it shows an error

Specified time is not supported in this calendar.

My code:

adapter = new MySqlDataAdapter(cmd);
adapter.Fill(dt);

foreach (DataRow row in dt.Rows)
{
     table.Rows.Add(row[1].ToString(), row[3].ToString(), row[0].ToString(), row[2].ToString(), row[4].ToString());
}

The problem is my code is working fine when I run it on my office PC, but on my laptop it shows this error.

Everything is the same

UPDATE : I'm using Arabic dates (hijri) .

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
progtariq
  • 43
  • 6
  • 2
    Do some debugging and try to understand what is different between both environments (office and your laptop). What is the format of the date returned from the database? Do the [CultureInfo.CurrentCulture](https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) or the [CultureInfo.CurrentCulture.DateTimeFormat](https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.datetimeformat(v=vs.110).aspx) match? – Rui Jarimba Jul 07 '18 at 09:36
  • im using arabic dates – progtariq Jul 07 '18 at 09:40
  • 1
    Oh BTW if you could edit your question and paste the full stacktrace of the exception that would be helpful. You need to give us more details. – Rui Jarimba Jul 07 '18 at 09:45
  • 1
    My bet is that the `CultureInfo.CurrentCulture` is not the same between your office PC and laptop. – Rui Jarimba Jul 07 '18 at 09:47
  • 3
    Are you saying that the error occurs in a call to `.ToString()`. Show us the stack trace. _How_ do you use the Hijri calendar in MySQL, how do you use it in the Operating System (regional settings etc.), and how do you use it in C# (is `CultureInfo.CurrentCulture.Calendar` a `System.Globalization.HijriCalendar`?)? – Jeppe Stig Nielsen Jul 07 '18 at 09:52
  • im sorry for being late im sorry but i dont know how to get stack trace ? can you help me with that? @RuiJarimba i copied my code from my office pc so nothing is different with the code . – progtariq Jul 07 '18 at 19:36
  • @JeppeStigNielsen i think it is from .ToString() and the date . MySQL Date supported range is '1000-01-01' to '9999-12-31'. and C# automatically change the datePicker dates to hijri when I changed the system locale and format to (Arabic (Saudi Arabia)). i didnt change anything in CultureInfo.currentCulture – progtariq Jul 07 '18 at 19:42
  • @progtariq see https://stackoverflow.com/a/4272629/558486 – Rui Jarimba Jul 08 '18 at 20:29

0 Answers0