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. Unable to read NULL DateTime value

Unable to read NULL DateTime value

Scheduled Pinned Locked Moved ASP.NET
databasehelpsharepointsaleslearning
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.
  • L Offline
    L Offline
    lupin68
    wrote on last edited by
    #1

    Here's my problem. I have a SQL db Table with a DateTime column. On my web app, I have a DataGrid that displays a list of info from that table (Order, Customer, Date of Delivery, etc..) When I read the DB, if the Date of Delivery doesn't exist I display nothing in the Cell. Alternately, When the order is delivered, the Date is displayed in that cell. The problem is this one: When there is no delivery date in the DB, the default on the DB is "01/01/1900 12:00AM". Now in my app, if I get the 01/01/1900 string for the Date, I don't display the value in the Cell. This was working fine until I installed the app and DB at the Customer. After running the app, the value for undelivered orders was displayed in the cell as 1/1/1900. So I changed my code again to check for the 01/01/1900 AND 1/1/1900 string and not display the value. This worked fine but I am not happy the way I check for the value of the date. After posting my problem in tan SQL forum, someone suggested to put the default value of that column to NULL, which is the logical thing to do. The only problem is that when I do that, I get an casting ERROR of my DateTime value (which is normal because NULL is not a Date value:zzz:) I'm reading from the DB. Here's my code to get the list of orders:sigh:: public static ArrayList GetAllOrders() { SqlDataReader reader = null; ArrayList orders = null; try { reader = SqlHelper.ExecuteReader(Resource.ConnectionString, CommandType.StoredProcedure, SP_GET_ORDERS, null); if (reader.HasRows) { orders = new ArrayList(); while (reader.Read()) { Order order = new Order(); order.WayBill = reader["WayBill"] as string; order.OrderDate = (DateTime)reader["OrderDate"]; order.Shipper.name = reader["Shipper"] as string; order.Items = (int)reader["Items"]; order.Weight = (int)reader["Weight"]; orders.Add(order); order = null; } } return orders; } This code reads a Stored Procedure where my order object has a OrderDate property casted to DateTime. Can anyone offer a suggestion/workaround for this problem.. Thanks a lot Pat

    B 1 Reply Last reply
    0
    • L lupin68

      Here's my problem. I have a SQL db Table with a DateTime column. On my web app, I have a DataGrid that displays a list of info from that table (Order, Customer, Date of Delivery, etc..) When I read the DB, if the Date of Delivery doesn't exist I display nothing in the Cell. Alternately, When the order is delivered, the Date is displayed in that cell. The problem is this one: When there is no delivery date in the DB, the default on the DB is "01/01/1900 12:00AM". Now in my app, if I get the 01/01/1900 string for the Date, I don't display the value in the Cell. This was working fine until I installed the app and DB at the Customer. After running the app, the value for undelivered orders was displayed in the cell as 1/1/1900. So I changed my code again to check for the 01/01/1900 AND 1/1/1900 string and not display the value. This worked fine but I am not happy the way I check for the value of the date. After posting my problem in tan SQL forum, someone suggested to put the default value of that column to NULL, which is the logical thing to do. The only problem is that when I do that, I get an casting ERROR of my DateTime value (which is normal because NULL is not a Date value:zzz:) I'm reading from the DB. Here's my code to get the list of orders:sigh:: public static ArrayList GetAllOrders() { SqlDataReader reader = null; ArrayList orders = null; try { reader = SqlHelper.ExecuteReader(Resource.ConnectionString, CommandType.StoredProcedure, SP_GET_ORDERS, null); if (reader.HasRows) { orders = new ArrayList(); while (reader.Read()) { Order order = new Order(); order.WayBill = reader["WayBill"] as string; order.OrderDate = (DateTime)reader["OrderDate"]; order.Shipper.name = reader["Shipper"] as string; order.Items = (int)reader["Items"]; order.Weight = (int)reader["Weight"]; orders.Add(order); order = null; } } return orders; } This code reads a Stored Procedure where my order object has a OrderDate property casted to DateTime. Can anyone offer a suggestion/workaround for this problem.. Thanks a lot Pat

      B Offline
      B Offline
      Bee Master
      wrote on last edited by
      #2

      Call IsDBNull method to check for null values before getting the value. //Start of joke Never comment ur code. If it was hard to write, it should be hard to understand !!! //End of joke

      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