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. Database & SysAdmin
  3. Database
  4. simple INSERT question

simple INSERT question

Scheduled Pinned Locked Moved Database
questionhelptutorial
2 Posts 2 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.
  • H Offline
    H Offline
    hkl
    wrote on last edited by
    #1

    When I try: INSERT INTO Product (ID, name, date) VALUES (123, NULL, NULL) It works fine when I use NULL to 'name' and 'date' in the INSERT statement. However, when I use a variable: INSERT INTO Product (ID, name, date) VALUES (123, @myName, NULL) And assign @myName.Value = null to the variable, I get an error message when I execute this statement. (For example: myInsert.Parameters["@myName"].Value = null;) My question is: If I use @myName in the INSERT statement, how I can assign NULL to it?? Thank you!!:)

    E 1 Reply Last reply
    0
    • H hkl

      When I try: INSERT INTO Product (ID, name, date) VALUES (123, NULL, NULL) It works fine when I use NULL to 'name' and 'date' in the INSERT statement. However, when I use a variable: INSERT INTO Product (ID, name, date) VALUES (123, @myName, NULL) And assign @myName.Value = null to the variable, I get an error message when I execute this statement. (For example: myInsert.Parameters["@myName"].Value = null;) My question is: If I use @myName in the INSERT statement, how I can assign NULL to it?? Thank you!!:)

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      You have to use DBNull.Value instead of null, e.g. myInsert.Parameters["@myName"].Value = 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