Enterprise Library IDataReader DateTime format

Locked Enterprise Library IDataReader DateTime format

  • Monday, May 14, 2012 8:37 PM
     
     

    I am using enterprise library to get the data from backend and used this command db.ExecuteReader(command) , it returns data in IDataReader and
    when I bind the data to the gridview the default datetime values are binding in this format 5/14/2012 10:50:55 PM and its not showing the milliseconds part.

    How to change the enterprise library  IDataReader Datetime format to 5/14/2012 22:50:55.968?

All Replies

  • Tuesday, May 15, 2012 12:06 AM
     
     

    Please check-out below link

    http://support.microsoft.com/kb/186265


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • Tuesday, May 15, 2012 1:43 PM
     
     
    The backend stores the value in this format 5/14/2012 22:50:55.968, but the problem is when I bind the value to the gridview or datatable the default value is showing in this format 5/14/2012 10:50:55 PM.  I am trying to display in this format 5/14/2012 22:50:55.968 and in this case I am binding the data dynamically to the gridview. So I am not able to even defien the eval expression to the particular field/column in gridview.
  • Tuesday, May 15, 2012 7:27 PM
     
     

    Can you check-out below thread

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2047ad81-bc45-4147-91d1-e67bcd50e866


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • Thursday, May 17, 2012 2:52 PM
     
     

    I think the below code will work, but is there a way to apply the format to the datareader instead of formating the data row by row and we are binding the data to the gridview dynamically and the datetime column/field position will change from one query to other query.

     if (reader.Read())
          {
            DateTime date = (DateTime)reader["someColumnName"];
            string strTime = String.Format("{dd.MM.yyyy hh:mm:ss.fff}", date);
          }

  • Thursday, May 17, 2012 8:05 PM
     
     Answered
    can you use 

    IDataRecord.GetDate


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.

  • Friday, May 18, 2012 8:45 AM
     
     Answered

    The DataReader is actually returning a SqlDateTime structure under the hood.  How it is being displayed is nothing to do with the DataReader itself, but is instead down to the UI (gridview).  Your code above implies your gridview is expecting a string - however most GridViews will accept a DateTime, which is better as ordering will work correctly (if you order your string it won't end up date time order).

    You don't say what GridView you're using (ASP.NET/WinForm/WPF). There are lots of examples online where you can read up on 'formatting a grid view column'.  If you provide more information about the kind of gridview you are using then you can be pointed in the right direction.


    thargy

    Craig Dean (MCPD)
    Chief Executive
    www.webappuk.com

    Please consider marking this as the answer if you have been genuinely helped!