Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datareader to insert Null Date

Datareader to insert Null Date

Scheduled Pinned Locked Moved ASP.NET
database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bubberz
    wrote on last edited by
    #1

    I want to be able to insert into the field if the user doesn't enter a date, but the only way I've gotten the code to work so far is by the following, then concatenating an SQL Statement. I'm using SPROCS just yet, but I will in the near future: Dim dEndDate As Date If IsDBNull(RDR("End Date")) Then dEndDate = "01/01/1900" Else dEndDate = RDR("End Date") End If I did try: If IsDBNull(RDR("End Date")) Then dEndDate = ctype(dbnull.value, date) ...but this didn't work.

    R 1 Reply Last reply
    0
    • B bubberz

      I want to be able to insert into the field if the user doesn't enter a date, but the only way I've gotten the code to work so far is by the following, then concatenating an SQL Statement. I'm using SPROCS just yet, but I will in the near future: Dim dEndDate As Date If IsDBNull(RDR("End Date")) Then dEndDate = "01/01/1900" Else dEndDate = RDR("End Date") End If I did try: If IsDBNull(RDR("End Date")) Then dEndDate = ctype(dbnull.value, date) ...but this didn't work.

      R Offline
      R Offline
      Regardt
      wrote on last edited by
      #2

      Hi I'm not sure that this will be answer your question Working with dates is usually a bit of a headache, even more if you are developing international software products.The only advice I can give you is to keep your dates always as date object, never use dates as string ex. dEndDate = "01/01/1900" dEndDate = New Date(1900, 1, 1) This will insure that you will not have date issues between your UI and DB. You would be able to assign a dbnull to RDR("End Date") ,if RDR("End Date") the column datatype is date, and it also nulls. If you retrieve the datatable directly from the DB the rules implied on the table in the DB will apply on the datacolumn If you create the datacolumn on the fly specief the DataType and AllowDBNull ex. Dim oColumn As New DataColumn("End Date") oColumn.DataType = System.Type.GetType("System.DateTime") oColumn.AllowDBNull = True Hope it helps. Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups