ronayers
asked on
inserting records using vb.net
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 )
myConnection.Open()
Dim myCommand As New SqlCommand(myInsertQuery, myConnection)
myCommand.ExecuteNonQuery( )
myConnection.Close()
End Sub
Any ideas?
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
myConnection.Open()
Dim myCommand As New SqlCommand(myInsertQuery, myConnection)
myCommand.ExecuteNonQuery(
myConnection.Close()
End Sub
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.