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. Visual Basic
  4. inserting records using vb.net

inserting records using vb.net

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsql-serversysadmin
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.
  • J Offline
    J Offline
    jds1207
    wrote on last edited by
    #1

    I am trying to insert record into and SQL Server 2000 database and I keep getting the following error: Cannot insert the value NULL into column 'ItemID', table 'RAM.dbo.Item_JS'; column does not allow nulls. INSERT fails. The statement has been terminated. The column ItemID is set to autonumber in the db. Here is my code: Dim myConnString As String = "Data Source=********;Initial Catalog=******;User ID=*****;Password=*****;" Dim myInsertQuery As String = "INSERT INTO Item_JS (ItemPartNumber, ItemSourceCode, ItemSupercede, ItemCost, ItemName, ItemListPrice, ItemLastUpdateDT, ItemStatus, ItemCreationDt, CompanyID, StoreID, BrandID, PackageID) VALUES('" & Trim(partnumber) & "', '" & Trim(sourcecode) & "', '" & Trim(supercede) & "', CONVERT(MONEY,'" & cost & "'), '" & Trim(itemname) & "', CONVERT(MONEY,'" & listprice & "'), '" & Trim(lastupdateDt) & "', '" & Trim(status) & "', '" & Trim(insertdate) & "', '" & Trim(companyID) & "', '" & Trim(storeID) & "', '" & Trim(brandID) & "', '" & Trim(packageID) & "'" & ")" Dim myConnection As New SqlConnection(myConnString) myConnection.Open() Dim myCommand As New SqlCommand(myInsertQuery, myConnection) myCommand.ExecuteNonQuery() myConnection.Close() Any Ideas? jds1207

    T 1 Reply Last reply
    0
    • J jds1207

      I am trying to insert record into and SQL Server 2000 database and I keep getting the following error: Cannot insert the value NULL into column 'ItemID', table 'RAM.dbo.Item_JS'; column does not allow nulls. INSERT fails. The statement has been terminated. The column ItemID is set to autonumber in the db. Here is my code: Dim myConnString As String = "Data Source=********;Initial Catalog=******;User ID=*****;Password=*****;" Dim myInsertQuery As String = "INSERT INTO Item_JS (ItemPartNumber, ItemSourceCode, ItemSupercede, ItemCost, ItemName, ItemListPrice, ItemLastUpdateDT, ItemStatus, ItemCreationDt, CompanyID, StoreID, BrandID, PackageID) VALUES('" & Trim(partnumber) & "', '" & Trim(sourcecode) & "', '" & Trim(supercede) & "', CONVERT(MONEY,'" & cost & "'), '" & Trim(itemname) & "', CONVERT(MONEY,'" & listprice & "'), '" & Trim(lastupdateDt) & "', '" & Trim(status) & "', '" & Trim(insertdate) & "', '" & Trim(companyID) & "', '" & Trim(storeID) & "', '" & Trim(brandID) & "', '" & Trim(packageID) & "'" & ")" Dim myConnection As New SqlConnection(myConnString) myConnection.Open() Dim myCommand As New SqlCommand(myInsertQuery, myConnection) myCommand.ExecuteNonQuery() myConnection.Close() Any Ideas? jds1207

      T Offline
      T Offline
      Tim Carmichael
      wrote on last edited by
      #2

      Have you tried inserting a value in the ItemID field? It is supposed to autonumber, but, from your comments, it doesn't appear to. For what its worth, I DETEST autonumber... it has and is causing me to get heartburn... rather than autonumber, use a transaction or something to get the last value used and increment it for your insert. Tim

      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