Primary key error



Hi,

In my VB.NET program the user can update a bunch of information.
Just before the update is put in the database, I first change one field by
putting _bak behind the text with:

mySQL = "UPDATE " + Project.GeneralLog + " SET " + GeneralLog.YPcode + " =
" + GeneralLog.YPcode + "+ '_BAK' "
mySQL += "WHERE " + GeneralLog.YPcode + " = '" + ypcode + "'"

myCMD = New SqlCommand(mySQL, conn)
Try
myCMD.ExecuteNonQuery()
Catch ae As SqlException
conn.Close()
Return False
End Try

After that I use INSERT TO to put the the changed data in.
In most tables it goes ok because the primary key is the field that gets
changed, but in the tables that have a seperate ID field to be the primary
key (because the field that is primary in the other tables can have double
entries in this table).

For these tables I get an error:

{"Violation of PRIMARY KEY constraint 'PK__OverallS__3214EC2775435199'.
Cannot insert duplicate key in object 'dbo.OverallStatus'. The statement has
been terminated."}

The table is created with:

mySQL = "CREATE TABLE " + Project.OverallStatus + " (ID BIGINT
IDENTITY(1,1) PRIMARY KEY, " + OverallStatus.YPcode + " VARCHAR(15), "
mySQL += OverallStatus.Datum + " DATETIME, "
mySQL += OverallStatus.Description + " VARCHAR(5000))"
myCMD = New SqlCommand(mySQL, conn)
Try
myCMD.ExecuteNonQuery()
Catch ae As SqlException
nOK = True
End Try

The INSTERT INTO command I use, is the same one as for putting the data in
the table in the first time, so that is working properly.

What am I doing wrong?

rg,
Eric

.