CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Saint Paul, Minnesota, US
    Posts
    91

    ADO: Getting Milliseconds

    Hi ...

    I am trying to get Milliseconds from a SQL Database using ADO. The code below will return 0 for the wMilliseconds.

    Any comments / solutions.
    Thanks,
    Chris


    Code:
        // Some code is removed for clarity
    
        _variant_t vTemp; 
        COleDateTime codtUpdateDateTime; 
    
        // Define ADO connection pointers
        _ConnectionPtr pConnection = NULL;
        _RecordsetPtr  pRecordset = NULL;
    
        try
        {
            // When we open the application we will open the ADO connection
            pConnection.CreateInstance(__uuidof(Connection));
    
            // Open the ado connection
            pConnection->Open(bstrConnect,"","",adConnectUnspecified);
            
            // Select all the records
            csSQL = "SELECT * FROM dbo.MacgowanTest00";
    
            // Create an instance of the database
            pRecordset.CreateInstance(__uuidof(Recordset));
                 
            // This is required to support the Sort Property
            pRecordset->CursorLocation = adUseClient;
                
            // Open the recordset
            pRecordset->Open(LPCTSTR(csSQL), 
                               pConnection.GetInterfacePtr(),
    	     	               adOpenDynamic,
    	    	               adLockOptimistic,
                               adCmdText);
    
            while (pRecordset->GetadoEOF() == VARIANT_FALSE)
            {
                vTemp = pRecordset->Fields->GetItem(L"UpdateDateTime")->Value;
    
                // Try to get the millisonds here 
                SYSTEMTIME sTime;
                codtUpdateDateTime = vTemp.date; 
                codtUpdateDateTime.GetAsSystemTime(sTime); 
                int ms=sTime.wMilliseconds;
            }
    
        }
        catch(...)
        {
            // handle error
        }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ADO: Getting Milliseconds

    Well..., why are you sure the "Milliseconds" must be non-zero?

  3. #3
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: ADO: Getting Milliseconds

    Chris,

    This could be a timer resolution problem. I have the same type of code in my computer and it does the same thing. I remember reading somewhere that the timer resolution in XP is about 15ms, so a search taking less than 15ms will show 0ms. If anyone can verify this correct or incorrect please step on my toes, I'd rather have that than incorrect information. Try putting a Sleep(30) in your code before "codtUpdateDateTime.GetAsSystemTime(sTime);" and then ck your time.
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured