Skip to Content
0
Former Member
Sep 29, 2006 at 02:00 PM

This entry already exists in the following tables (ODBC -2035)

6795 Views

I have a usertable and I am trying to add a record to it. The usertable isn't linked to an object.

Some times this works fine, other times I get error "This entry already exists in the following tables (ODBC -2035)". I have of course checked that the record does not already exist!

Here is my code. "Echo" is a function that makes a debugging log, the log appears below.

'sParentItemKey = item key e.g. "B1000"
'LastRowNumber = integer
'key in 'OCHBOSCL' table will be in form "B1000.1"

'add a new record to the child table
Echo("Need to add new row")
'
Dim oUDT As SAPbobsCOM.UserTable
oUDT = oCompany.UserTables.Item("OCHBOSCL")
Echo("oUDT status: " & oUDT.GetAsXML.ToString & vbCrLf & "Table/code: " & oUDT.TableName.ToString & " " & oUDT.Code.ToString)
'
LastRowNumber = LastRowNumber + 1
Dim sUDTKey As String = sParentItemKey & "." & LastRowNumber
Echo(vbTab & "New OCHBOSCL key=" & sUDTKey)
oUDT.Code = sUDTKey
'
oEdit = oColumns.Item("ChildName").Cells.Item(Row).Specific()
sValue = Trim(oEdit.Value)
Echo(vbTab & "Name = " & sValue)
oUDT.Name = sValue
'
oUDT.UserFields.Fields.Item("U_Parent").Value = sParentItemKey
'
oEdit = oColumns.Item("ChildItm").Cells.Item(Row).Specific()
sValue = Trim(oEdit.Value)
Echo(vbTab & "U_ChildItm = " & sValue)
oUDT.UserFields.Fields.Item("U_ChildItm").Value = sValue
'
'I also update a couple more user fields here as above, removed for clarity
'
Echo("udt code before .add = " & oUDT.Code.ToString)
Echo("udt XML before .add = " & oUDT.GetAsXML.ToString)
'
Dim AddResult As Integer = oUDT.Add
Echo("Add UDT = " & AddResult)
'
Echo("udt code after .add = " & oUDT.Code.ToString)
Echo("udt XML after add = " & oUDT.GetAsXML.ToString)
'
If AddResult = -2035 Then
    Echo("2035 bug")
End If
'
If AddResult = 0 Then
    Echo("Record Added. Key is: " & oCompany.GetNewObjectKey())
Else
    Echo("Add record error: " & oCompany.GetLastErrorCode & ": " & oCompany.GetLastErrorDescription.ToString)
End If

Need to add new row
oUDT status: <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL/></BO></BOM>
Table/code: OCHBOSCL 

	New OCHBOSCL key=B1000.1
	Name = Boxing Gloves
	U_ChildItm = A1000

udt code before .add = B1000.1
udt XML before .add = <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL><row><Code>B1000.1</Code><Name>Boxing Gloves</Name><U_Parent>B1000</U_Parent><U_ChildItm>A1000</U_ChildItm><U_Quantity>99</U_Quantity><U_Prefer>N</U_Prefer><U_Mand>N</U_Mand></row></OCHBOSCL></BO></BOM>

Add UDT = -2035

udt code after .add = B1000.1
udt XML after add = <?xml version="1.0" encoding="UTF-16"?><BOM><BO><AdmInfo><Object>-3</Object></AdmInfo><OCHBOSCL><row><Code>B1000.1</Code><Name>Boxing Gloves</Name><U_Parent>B1000</U_Parent><U_ChildItm>A1000</U_ChildItm><U_Quantity>99</U_Quantity><U_Prefer>N</U_Prefer><U_Mand>N</U_Mand></row></OCHBOSCL></BO></BOM>

2035 bug

Add record error: -2035: This entry already exists in the following tables (ODBC -2035)

You can see from the debug log that the data is being copied into the usertable object as it appears in the XML for the usertable. I tried adding a ".update" after .add but this didn't work. The data is definately not being added to the database.

Does SBO have some sort of key index that could have an old reference to a record with the same key on it?

I've been looking at this for hours, looked at loads of other examples and I just can't see the problem.

Thanks for any help you can offer.

Darren