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. General Programming
  3. C#
  4. DBNull error

DBNull error

Scheduled Pinned Locked Moved C#
help
4 Posts 4 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.
  • K Offline
    K Offline
    kanchoette
    wrote on last edited by
    #1

    Although I have all datatable columns set to accept DBNull, my application throws this exception:

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public System.DateTime ArrangementDate {
    get {
    try {
    return ((global::System.DateTime)(this[this.tablePaymentArrangements.ArrangementDateColumn]));
    }
    catch (global::System.InvalidCastException e) {
    throw new global::System.Data.StrongTypingException("The value for column \'ArrangementDate\' in table \'PaymentArrangements\' is DBNull.", e);
    }
    }
    set {
    this[this.tablePaymentArrangements.ArrangementDateColumn] = value;
    }
    }

    I'm stumped (right now). Any pointers would be much appreciated please.

    J M P 3 Replies Last reply
    0
    • K kanchoette

      Although I have all datatable columns set to accept DBNull, my application throws this exception:

      [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
      public System.DateTime ArrangementDate {
      get {
      try {
      return ((global::System.DateTime)(this[this.tablePaymentArrangements.ArrangementDateColumn]));
      }
      catch (global::System.InvalidCastException e) {
      throw new global::System.Data.StrongTypingException("The value for column \'ArrangementDate\' in table \'PaymentArrangements\' is DBNull.", e);
      }
      }
      set {
      this[this.tablePaymentArrangements.ArrangementDateColumn] = value;
      }
      }

      I'm stumped (right now). Any pointers would be much appreciated please.

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      If that is a strongly typed dataset, you'll find it has an bool IsArrangementDateNull() method. You should use this to check before trying to read the value. The reason for this is there is no way to cast DBNull.value to a DateTime.

      1 Reply Last reply
      0
      • K kanchoette

        Although I have all datatable columns set to accept DBNull, my application throws this exception:

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public System.DateTime ArrangementDate {
        get {
        try {
        return ((global::System.DateTime)(this[this.tablePaymentArrangements.ArrangementDateColumn]));
        }
        catch (global::System.InvalidCastException e) {
        throw new global::System.Data.StrongTypingException("The value for column \'ArrangementDate\' in table \'PaymentArrangements\' is DBNull.", e);
        }
        }
        set {
        this[this.tablePaymentArrangements.ArrangementDateColumn] = value;
        }
        }

        I'm stumped (right now). Any pointers would be much appreciated please.

        M Offline
        M Offline
        monstale
        wrote on last edited by
        #3

        Hi, I think DBNull is not compatible with DateTime. You should check if it is DBNull.Value and then send null back. ;-) greetz

        1 Reply Last reply
        0
        • K kanchoette

          Although I have all datatable columns set to accept DBNull, my application throws this exception:

          [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
          public System.DateTime ArrangementDate {
          get {
          try {
          return ((global::System.DateTime)(this[this.tablePaymentArrangements.ArrangementDateColumn]));
          }
          catch (global::System.InvalidCastException e) {
          throw new global::System.Data.StrongTypingException("The value for column \'ArrangementDate\' in table \'PaymentArrangements\' is DBNull.", e);
          }
          }
          set {
          this[this.tablePaymentArrangements.ArrangementDateColumn] = value;
          }
          }

          I'm stumped (right now). Any pointers would be much appreciated please.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          DateTime is not nullable.

          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