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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Assigning a null value

Assigning a null value

Scheduled Pinned Locked Moved C#
question
6 Posts 4 Posters 1 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.
  • A Offline
    A Offline
    ArielR
    wrote on last edited by
    #1

    How can assign a null value to a field that is integer but allows null value.? int? nullval = null; mydataSet.mytable[myBindingSource.Position].myIntField = nullval ; isn't found.....

    L P 2 Replies Last reply
    0
    • A ArielR

      How can assign a null value to a field that is integer but allows null value.? int? nullval = null; mydataSet.mytable[myBindingSource.Position].myIntField = nullval ; isn't found.....

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Have you tried DBNull.Value? regards

      A 1 Reply Last reply
      0
      • L Lost User

        Have you tried DBNull.Value? regards

        A Offline
        A Offline
        ArielR
        wrote on last edited by
        #3

        yes, when compile have this error: "cannot implicitly convert type 'System.DBNull.value' to int"

        D 1 Reply Last reply
        0
        • A ArielR

          yes, when compile have this error: "cannot implicitly convert type 'System.DBNull.value' to int"

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Of course not. You have to rewrite that little bit of assignment code you posted to check for a null value in the int, and then, if null, you have to assign DBNull.Value to your database column.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          A 1 Reply Last reply
          0
          • A ArielR

            How can assign a null value to a field that is integer but allows null value.? int? nullval = null; mydataSet.mytable[myBindingSource.Position].myIntField = nullval ; isn't found.....

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

            You don't need the local variable.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              Of course not. You have to rewrite that little bit of assignment code you posted to check for a null value in the int, and then, if null, you have to assign DBNull.Value to your database column.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              A Offline
              A Offline
              ArielR
              wrote on last edited by
              #6

              I solved it that way... mydataSet.mytable[myBindingSource.Position].SetmyIntFieldNull(); Thank you very much...

              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