inserting records using

Posted on 2007-07-31
Last Modified: 2013-11-26
I am trying to insert records into an 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. It is not a null value.  Here is my code:

Private Sub InsertRecord(ByVal partnumber As String, ByVal sourcecode As String, ByVal supercede As String, ByVal cost As String, ByVal itemname As String, ByVal listprice As String, ByVal lastupdateDt As String, ByVal status As String, ByVal insertdate As String, ByVal companyID As String, ByVal storeID As String, ByVal brandID As String, ByVal packageID As String)
        'Insert records into database table.
        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)
        Dim myCommand As New SqlCommand(myInsertQuery, myConnection)
    End Sub

Any ideas?
Question by:ronayers
    1 Comment
    LVL 38

    Accepted Solution

    >The column ItemID is set to autonumber in the db.
    First I would double check that this field has Identity set to true...  If this was converted from Access, you will need to do this manually.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now