Losing milliseconds setting Recordset field to DateTime RRS feed

  • Question

  • I have a C# project and added a reference to the ADO 6.1 dll (so it created an interop assembly for me - Interop.ADOB.6.1 - in my references).

    In my code I create a Recordset with a single datetime field (adDBTimeStamp data type). When I set the field to a DateTime value that contains milliseconds the milliseconds get rounded to the nearest second.


            static void Test()

                ADODB.Recordset rs = new ADODB.Recordset();
                rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
                ADODB.FieldAttributeEnum eAttributes = ADODB.FieldAttributeEnum.adFldUpdatable | ADODB.FieldAttributeEnum.adFldIsNullable | ADODB.FieldAttributeEnum.adFldMayBeNull | ADODB.FieldAttributeEnum.adFldFixed | ADODB.FieldAttributeEnum.adFldLong;
                rs.Fields.Append("MyDate", ADODB.DataTypeEnum.adDBTimeStamp, 8, eAttributes);


                DateTime expected = new DateTime(2004, 4, 5, 7, 19, 2, 577);
                rs.Fields["MyDate"].Value = expected;
                DateTime actual = Convert.ToDateTime(rs.Fields["MyDate"].Value);
                if (actual != expected)
                    Console.WriteLine("Actual = {0}, Expected = {1}", actual.ToString("yyyy-MM-dd HH:mm:ss:fff"), expected.ToString("yyyy-MM-dd HH:mm:ss:fff"));

    The strange thing is that if I open the recordset using a query that returns a datetime with milliseconds then I do see the milliseconds in the Recordset field value (and I verified the field data type is adDBTimeStamp also), so it would seem like the adDBTimeStamp is the right data type for the Recordset field and it is capable of storing milliseconds but I can't programatically set the value to something with milliseconds.

    Any ideas?? 

    - Brad

    Monday, July 22, 2013 4:43 PM


All replies

  • Hi Brad,

    Thanks for your post. However, I'm afraid ADO is not a general ADO.NET question. I'll move your thread to "Where is the forum for" to look for a better forum. I guess it might be a Windows desktop development question.

    Sorry for any inconvenience.

    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Wednesday, July 24, 2013 8:46 AM
  • Does this help at all?



    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Wednesday, July 24, 2013 9:14 PM
  • Thanks, but that doesn't help. I can correctly retrieve a datetime with milliseconds from the DB, but I can't set that field in the Recordset to a DateTime with milliseconds without it rounding to the nearest second.  

    For now I have changed my code to create the field using adDate for the data type and it seems to be working ok. That doesn't help me when the Recordset is created as the result of executing a query though.

    - Brad

    Sunday, July 28, 2013 5:13 PM
  • Might ask them here;


    about converting your code to use an ADO.NET data provider.




    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    Sunday, July 28, 2013 5:21 PM