none
datetime in a conflict on ClientUpdateServerUpdate RRS feed

  • Question

  • I have used the example in sync framework documentation for How to: Handle Data Conflicts and Errors. (2.1). In the example in case "CU": we go through the columns that differ on client and server.

    The sample just uses some string-concatenation. In my solution I changed it so I can have a switch for wheather client or server wins. Different on different columns. I want to handle different datatypes such as DateTime as well. It seems there are some internals at work here, because it just doesnt work...

    I have tried multiple types of ToString(...) overloads but none seems to get it right. I have also tried just setting a DateTime-object on there.

    My (simplified) code:

    conflictingColumnsList.All(x =>
    {
    string newValue = x.serverValue.ToString();
    switch (x.datatype)
    {
    case "System.DateTime":
    table.Rows[i][x.columnName] = Convert.ToDateTime(newValue);
    break;
    }

    The exception I get is
    [2196] String was not recognized as a valid DateTime.Couldn't store <24.12.2012> in timestampStart Column.  Expected type is DateTime.

    However I provide the date I get day and month switched. I have output on my newValue-string and I know that converted to a datetime it is the correct date. I have tried
    table.Rows[i][x.columnName] = Convert.ToDateTime(newValue).ToString("yyyy-MM-dd");
    and also to switch day and month
    table.Rows[i][x.columnName] = Convert.ToDateTime(newValue).ToString("yyyy-dd-MM");
    but still all the same. This of course works if day is 12 or less, but the date is all wrong in the database.


    Any thoughts anyone?

    Wednesday, October 3, 2012 2:18 PM

Answers

  • ohh my.
    turns out 
    table.Rows[i][x.columnName] = Convert.ToDateTime(newValue);
    works just fine.

    I had an old
    table.Rows[i][x.columnName] = newValue;
    outside my switch(datatype)-statement from before I added support for different datatypes. Discovered when I was able to debug properly.

    Thanks for your help though :)

    • Marked as answer by johneven Thursday, October 4, 2012 9:14 AM
    Wednesday, October 3, 2012 4:00 PM

All replies

  • try DateTime.TryParseExact
    Wednesday, October 3, 2012 2:49 PM
    Moderator
  • ohh my.
    turns out 
    table.Rows[i][x.columnName] = Convert.ToDateTime(newValue);
    works just fine.

    I had an old
    table.Rows[i][x.columnName] = newValue;
    outside my switch(datatype)-statement from before I added support for different datatypes. Discovered when I was able to debug properly.

    Thanks for your help though :)

    • Marked as answer by johneven Thursday, October 4, 2012 9:14 AM
    Wednesday, October 3, 2012 4:00 PM