inserting records using vb.net
-
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 -
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? jds1207Have 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