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. how to assign a null value to an int

how to assign a null value to an int

Scheduled Pinned Locked Moved C#
tutorialdatabasehelp
3 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.
  • Q Offline
    Q Offline
    quiteSmart
    wrote on last edited by
    #1

    hi, i just want to ask if there is a way to asign a null value to a variable of type int. for example i can write this: String testingString = null; while writting this gives an error: int testingInteger = null; The error is: Can not convert null to 'int' because it is a value type i am using this to assign a null value in database. meaning the textbox the i take from it the value of the integer is empty i want to insert a null value in the database not an empty cell. thanks in advance,

    C P 2 Replies Last reply
    0
    • Q quiteSmart

      hi, i just want to ask if there is a way to asign a null value to a variable of type int. for example i can write this: String testingString = null; while writting this gives an error: int testingInteger = null; The error is: Can not convert null to 'int' because it is a value type i am using this to assign a null value in database. meaning the textbox the i take from it the value of the integer is empty i want to insert a null value in the database not an empty cell. thanks in advance,

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

      quiteSmart wrote:

      i just want to ask if there is a way to asign a null value to a variable of type int

      If you are using .NET 2.0 you can use nullable types. You just add a question mark to the value type to make it nullable:

      int? myVariable = null;

      quiteSmart wrote:

      i am using this to assign a null value in database.

      Just remember that when you are assigning null to a database you have to convert it to a System.DBNull.Value


      Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

      1 Reply Last reply
      0
      • Q quiteSmart

        hi, i just want to ask if there is a way to asign a null value to a variable of type int. for example i can write this: String testingString = null; while writting this gives an error: int testingInteger = null; The error is: Can not convert null to 'int' because it is a value type i am using this to assign a null value in database. meaning the textbox the i take from it the value of the integer is empty i want to insert a null value in the database not an empty cell. thanks in advance,

        P Offline
        P Offline
        Parwej Ahamad
        wrote on last edited by
        #3

        Because................ String is a reference type and int is value type........

        Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

        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