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. Database & SysAdmin
  3. Database
  4. Making a field null

Making a field null

Scheduled Pinned Locked Moved Database
questiondatabaseannouncementlearning
6 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.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron

    D C D 3 Replies Last reply
    0
    • M myNameIsRon

      Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron

      D Offline
      D Offline
      dadax_85
      wrote on last edited by
      #2

      try this myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = ""; dadax_85@hotmail.com

      C 1 Reply Last reply
      0
      • M myNameIsRon

        Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Instead of null, use System.DBNull.Value. This is because in certain cases you will need to distinguish between a C# null and a database null. For example, in the case of ExecuteScalar a null result means that there was no result (i.e. the answer did not exist) whereas if ExecuteScalar returns DBNull.Value then the answer from the database is null (i.e. there is an answer, and the answer is null). See MSDN: System.DBNull[^] Does this help?


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        M 1 Reply Last reply
        0
        • D dadax_85

          try this myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = ""; dadax_85@hotmail.com

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          That won't work either. An empty string is not null, it is a string of zero length.


          "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            Instead of null, use System.DBNull.Value. This is because in certain cases you will need to distinguish between a C# null and a database null. For example, in the case of ExecuteScalar a null result means that there was no result (i.e. the answer did not exist) whereas if ExecuteScalar returns DBNull.Value then the answer from the database is null (i.e. there is an answer, and the answer is null). See MSDN: System.DBNull[^] Does this help?


            "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

            M Offline
            M Offline
            myNameIsRon
            wrote on last edited by
            #5

            I tip my hat to you Colin, thanks!!! I have another issue with changing the field to DBNull... but I think this is a C# issue with binding textbox with DataTable and so I'll post it there as well. I'm not able to: if (txb_Number.Text == "") { //this never occurs because the textbox reverts to the original bound Long Integer value } I can only change the bound data if a new number is used. A blank textbox (or letters entered) only reverts back to the origninal value. I want to update the field to DBNull if the textbox is empty. Ron

            1 Reply Last reply
            0
            • M myNameIsRon

              Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron

              D Offline
              D Offline
              dansoft
              wrote on last edited by
              #6

              Hi Ron, Please try the following myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = DBNull.Value or myCommand.Parameters.Add("@Number", DBNull.Value)

              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