Results 1 to 6 of 6

Thread: placing DbNull into "ToShortDateString'

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    placing DbNull into "ToShortDateString'

    When I try to place a null value into my datagrid, I get this error. Is there a way around this?

    Public member 'ToShortDateString' on type 'DBNull' not found

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Sounds like you are attempting to convert that to a short date time.

    Search your code for toShortDateString and when you find it, see if it would be accessing that field. If so, then you need to do an IF statement. if not isdbnull(...) then ...
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    heres the code for the column in the datagrid. It's on the HTML side. Can I do a isDbNull check on it still?

    Code:
    <asp:TemplateColumn SortExpression="DISPLAY_START_DATE" HeaderText="DISPLAY START DATE">
    									<ItemTemplate>
    										<%# Container.DataItem ("Display_Start_Date").ToShortDateString()%>
    									</ItemTemplate>
    								</asp:TemplateColumn>

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    <%# IIF(IsDBNull(Container.DataItem ("Display_Start_Date")), "", Container.DataItem ("Display_Start_Date").ToShortDateString() %>
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I'm getting the same error. It bombs out when I try to bind the data at this line: DataGrid1.DataBind(). Could it be cause the codes on the HTML side?

    Public member 'ToShortDateString' on type 'DBNull' not found

  6. #6
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    Perhaps this is what you are looking for:

    Code:
                    <asp:BoundColumn DataField="Display_Start_Date" HeaderText="DISPLAY START DATE" DataFormatString="{0:d}"></asp:BoundColumn>
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

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