Results 1 to 7 of 7

Thread: [2008] Details DataFormatString

  1. #1

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    [2008] Details DataFormatString

    I know Google lights up like a Christmas tree when you search for something regarding date format in ASP.NET but I'm still having a problem with a BoundField and formatting its date.

    ExpiryDate is varchar2(4000) in dd/mm/yyyy format.
    SQL (Oracle 9i):
    sql Code:
    1. select
    2.   ag.AGREEMENTS_ABBR LicensorNumber,
    3.   (select r1.FIELD_VALUE
    4.   from V_REPCUSTOMFIELDDATA r1
    5.   where
    6.     r1.INTERNAL_DESCRIPTIONS_CODE = 21
    7.     and r1.ASSOCIATED_WITH_CODE = ag.AGREEMENTS_ABBR) ContractName,
    8.   ag.AGREEMENTS_NAME ProjectName,
    9.   ag.AGREEMENTS_AVAILDATE AvailableDate,
    10.   to_date(ag.AGREEMENTS_EXPLEXPIRES, 'dd/mm/yyyy') ExpiryDate,
    11.   (select to_date(r2.FIELD_VALUE, 'dd-mon-yyyy')
    12.   from V_REPCUSTOMFIELDDATA r2
    13.   where
    14.     r2.INTERNAL_DESCRIPTIONS_CODE = 35
    15.     and r2.ASSOCIATED_WITH_CODE = ag.AGREEMENTS_ABBR) SellOffDate,
    16.   ag.FREQ_DISPLAY ReportFrequency
    17. from V_AGREEMENT ag
    18. where ag.AGREEMENTS_ABBR = :licensorNum

    DetailsView:
    Code:
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False">
                <Fields>
                    <asp:BoundField DataField="LicensorNumber" HeaderText="Licensor Number" />
                    <asp:BoundField DataField="ProjectName" HeaderText="Project Name" />
                    <asp:BoundField DataField="AvailableDate" 
                        DataFormatString="{0:MM/dd/yyyy}" HeaderText="Start Date" 
                        HtmlEncode="False" />
                    <asp:BoundField DataField="ExpiryDate" 
                        DataFormatString="{0:MM/dd/yyyy}" HeaderText="Expiry Date" 
                        HtmlEncode="False" />
                    <asp:BoundField DataField="SellOffDate" HeaderText="Sell Off Date" 
                        DataFormatString="{0:MM/dd/yyyy}" 
                        HtmlEncode="False" />
                    <asp:BoundField DataField="ReportFrequency" HeaderText="Reporting Frequency" />
                </Fields>
            </asp:DetailsView>
    SellOffDate (also a varchar2(4000)) appears formatted correctly in my DetailsView. ExpiryDate appears formatted as "12/31/99 12:00:00AM" in my Details View.

    What simple thing am I missing this time?

    EDIT: Please note that I cannot change the Data Types in the database.
    EDIT2: Nuts - meant to say DetailsView in the title, of course.
    Last edited by nmadd; Apr 22nd, 2008 at 01:58 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2008] Details DataFormatString

    Month is upper case MM, not lower case mm (that's minutes or something).

    Change your expiry date format to dd/MM/yyyy
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  3. #3

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Details DataFormatString

    Quote Originally Posted by Tom Sawyer
    Month is upper case MM, not lower case mm (that's minutes or something).

    Change your expiry date format to dd/MM/yyyy
    Thanks Tom. I gave it a shot but that doesn't seem to be the problem. As far as I know, Oracle doesn't care if it's mm or MM. The DataFormatStrings in my DetailsView do use the correct MM though.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2008] Details DataFormatString

    It may be something to do with the to_date function then. Is the Expiry Date null or not a valid date? Since you're forcing it into a format, null and invalid values may be set to a default value and that may be it.

    Try running the query in Query Analyzer (or whatever the Oracle equivalent is called) with the to_date removed and see what's in the field. If it's null or an invalid date, you may need to add a check for that before doing any formatting.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Details DataFormatString

    Oracle doesn't care if it's mm or MM as it's not relevant to string formatting. The string formatting occurs after the data comes back to 'the code', where it is then being formatted. So it's the .NET code that cares whether it's mm or MM.

    Therefore, why not return the date as-is from Oracle and format in the code?

  6. #6

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Details DataFormatString

    Quote Originally Posted by mendhak
    Therefore, why not return the date as-is from Oracle and format in the code?
    Sounds easy enough. My problem is, I'm not entirely sure where to do this in my code.
    I get my DataTable as such:
    vb.net Code:
    1. Dim ldBLL As New LicensorDetailBLL()
    2. Dim dt1 As Data.DataTable = ldBLL.GetLicensorDetail(licensorNum)
    3. Me.DetailsView1.DataSource = dt1
    4. Me.DetailsView1.DataBind()
    I'm unsure where I should convert my ExpiryDate field to a Date and format it appropriately. Shall I create a new DataColumn and copy the old ExpiryDate column over to it and convert to DateTime? Can I create a new DataColumn with an Expression that converts to DateTime?

    Thanks for a push in the right direction.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Details DataFormatString

    It does have a databound event in which you could manipulate the values.

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