inserting records using vb.net

Posted on 2007-07-31
Medium Priority
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

PaulHews earned 1500 total points
ID: 19601224
>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.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

862 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