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 in Tpyed Datasets

DBNull in Tpyed Datasets

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 3 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.
  • T Offline
    T Offline
    topcatalpha
    wrote on last edited by
    #1

    Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt

    J J 2 Replies Last reply
    0
    • T topcatalpha

      Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt

      J Offline
      J Offline
      Justin Perez
      wrote on last edited by
      #2

      I'm not quite sure I understand your question, but if I understand correctly, DBNull.Value, will give you a null value you can pass.

      I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

      T 1 Reply Last reply
      0
      • J Justin Perez

        I'm not quite sure I understand your question, but if I understand correctly, DBNull.Value, will give you a null value you can pass.

        I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

        T Offline
        T Offline
        topcatalpha
        wrote on last edited by
        #3

        hi, thx for u'r response. (i rather be polite thinking you're invention maybe exists. :-) ) Its a column from a typed dataset, which has no value entered by the user. so the value is DBnull. When getting my value to pass to a stored proc it results in an error. Typed dataset DataSet1 with Table1 has 3 columns all integers with property allow DBnull Gives a row Table1Row with fields Table1Row.ID1, Table1Row.ID2, Table1Row.ID3 when calling for example Table1Row.ID2 it gives an error. In designtime the property Nullvalue also remains (throw exception) and cannot be modified. For string fields it's no problem. Thx again. :-) Kurt

        J 1 Reply Last reply
        0
        • T topcatalpha

          hi, thx for u'r response. (i rather be polite thinking you're invention maybe exists. :-) ) Its a column from a typed dataset, which has no value entered by the user. so the value is DBnull. When getting my value to pass to a stored proc it results in an error. Typed dataset DataSet1 with Table1 has 3 columns all integers with property allow DBnull Gives a row Table1Row with fields Table1Row.ID1, Table1Row.ID2, Table1Row.ID3 when calling for example Table1Row.ID2 it gives an error. In designtime the property Nullvalue also remains (throw exception) and cannot be modified. For string fields it's no problem. Thx again. :-) Kurt

          J Offline
          J Offline
          Justin Perez
          wrote on last edited by
          #4

          topcatalpha wrote:

          thx for u'r response. (i rather be polite thinking you're invention maybe exists. )

          :laugh:

          topcatalpha wrote:

          When getting my value to pass to a stored proc it results in an error.

          What is the error message you are recieving?

          I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

          T 1 Reply Last reply
          0
          • J Justin Perez

            topcatalpha wrote:

            thx for u'r response. (i rather be polite thinking you're invention maybe exists. )

            :laugh:

            topcatalpha wrote:

            When getting my value to pass to a stored proc it results in an error.

            What is the error message you are recieving?

            I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

            T Offline
            T Offline
            topcatalpha
            wrote on last edited by
            #5

            The error message is : The value for column 'ID2' in table 'Table1' is DBNull

            J 1 Reply Last reply
            0
            • T topcatalpha

              The error message is : The value for column 'ID2' in table 'Table1' is DBNull

              J Offline
              J Offline
              Justin Perez
              wrote on last edited by
              #6

              Double check that the field ID2 does allow null values, that make sure that there isn't a exception thrown if there is a null value. Additionally, in your code, you can check the value before passing it, and if it is equal to DBNull then set the value to 0 instead of null.

              I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

              T 1 Reply Last reply
              0
              • J Justin Perez

                Double check that the field ID2 does allow null values, that make sure that there isn't a exception thrown if there is a null value. Additionally, in your code, you can check the value before passing it, and if it is equal to DBNull then set the value to 0 instead of null.

                I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer

                T Offline
                T Offline
                topcatalpha
                wrote on last edited by
                #7

                Found something : [^] i need to check each field for null and pass null value myself. Seems very unlogic to me knowning that SQL servers allow DBnull values in tables. Ex : if(Table1Row.IsID2Null()) ATDatabase.AddInParameter(updateCommand, "ID2", DbType.Int32, null); else ATDatabase.AddInParameter(updateCommand, "ID2", DbType.Int32, Table1Row.ID2); Checking the auto generated code from the typed dataset: [System.Diagnostics.DebuggerNonUserCodeAttribute()] public long ID2 { get { try { return ((long)(this[this.Table1.ID2Column])); } catch (System.InvalidCastException e) { throw new System.Data.StrongTypingException("The value for column \'ID2\' in table \'Table1\' is DBNull.", e); } } set { this[this.Table1.ID2Column] = value; } } Cannot pass null value here... greetz Kurt

                1 Reply Last reply
                0
                • T topcatalpha

                  Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt

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

                  IIRC a typed dataset generates 2 methods for you: Is_ColumnName_Null() Set_ColumnName_Null()

                  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