Hello,
I am working on trying to populate a SQL table with data from a free table. I created a program using Visual FoxPro 9.0 to do this, but
I am having a problem with a violation of primary key contraint.
The SQL table ArCustStkXref has 3 fields
Customer (c,7) PK
CustStockCode (c,30) PK
StockCode (c,30)
Keys: ArCustStkXrefKey
Indexes:
ArCustStkXrefIdxStk (Unique, Non-Clustered)
ArCustStkXrefKey (Clustered)
The purpose of this table is to provide a cross-reference between our part numbers and that of our customers.
During normal input from the application that handles this data the customer field can be dupplicated across many records, I can manually modify records
and input dupplicate customer numbers, but I am not being able to do this with FoxPro. I get the following error:
Violation of PRIMARY KEY contraint 'ArCustStkXrefKey'. Cannot insert dupplicate key in object 'dbo.ArCustStkXref'
The free table has 2 fields ssku (c,10) and stockcode (c,20)
I will greatly appreciate any feedback you can provide.
Mike.
* Program.: LpSKU.PRG V1.0
*
CLOSE ALL
CLEAR
SET DEFAULT TO C:\Projects\lpsku
SET NULL OFF
*
DELETE FILE C:\Projects\lpsku\vlpsku*.*
*
CREATE DATABASE vlpsku
CREATE SQL VIEW vlpsku;
REMOTE CONNECTION LocalSysPro;
AS select Customer, CustStockCode, StockCode FROM ArCustStkXref;
ORDER BY CustStockCode
*
DBSETPROP ("vlpsku", "View", "SendUpdates", .T.)
DBSETPROP("vlpsku" , "VIEW","WhereType",3)
*
DBSETPROP("vlpsku.Customer", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.Customer", "Field", "UpdateName", [ArCustStkXref.Customer])
DBSETPROP("vlpsku.Customer", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.CustStockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.CustStockCode", "Field", "UpdateName", [ArCustStkXref.CustStockCode])
DBSETPROP("vlpsku.CustStockCode", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.StockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.StockCode", "Field", "UpdateName", [ArCustStkXref.StockCode])
DBSETPROP("vlpsku.StockCode", "Field", "KeyField", .F.)
*
SELECT 1
USE vlpsku
*
SELECT 2
USE lpsku INDEX stock
*
GO TOP
SCATTER MEMVAR
*
DO WHILE .NOT. EOF()
*
SELECT 1
*
INSERT INTO vlpsku (Customer, CustStockCode, StockCode);
VALUES("39050",m.ssku,m.StockCode)
*
IF NOT TABLEUPDATE(1, .t., [vlpsku])
AERROR(laError)
MessageBox([Can not Update vlpsku ]+laError[1,2])
EXIT
ENDIF
*
SELECT 2
*
IF .NOT. EOF()
SKIP
SCATTER MEMVAR
LOOP
ENDIF
*
ENDDO
*
CLOSE DATABASES ALL
*
RETURN
I am working on trying to populate a SQL table with data from a free table. I created a program using Visual FoxPro 9.0 to do this, but
I am having a problem with a violation of primary key contraint.
The SQL table ArCustStkXref has 3 fields
Customer (c,7) PK
CustStockCode (c,30) PK
StockCode (c,30)
Keys: ArCustStkXrefKey
Indexes:
ArCustStkXrefIdxStk (Unique, Non-Clustered)
ArCustStkXrefKey (Clustered)
The purpose of this table is to provide a cross-reference between our part numbers and that of our customers.
During normal input from the application that handles this data the customer field can be dupplicated across many records, I can manually modify records
and input dupplicate customer numbers, but I am not being able to do this with FoxPro. I get the following error:
Violation of PRIMARY KEY contraint 'ArCustStkXrefKey'. Cannot insert dupplicate key in object 'dbo.ArCustStkXref'
The free table has 2 fields ssku (c,10) and stockcode (c,20)
I will greatly appreciate any feedback you can provide.
Mike.
* Program.: LpSKU.PRG V1.0
*
CLOSE ALL
CLEAR
SET DEFAULT TO C:\Projects\lpsku
SET NULL OFF
*
DELETE FILE C:\Projects\lpsku\vlpsku*.*
*
CREATE DATABASE vlpsku
CREATE SQL VIEW vlpsku;
REMOTE CONNECTION LocalSysPro;
AS select Customer, CustStockCode, StockCode FROM ArCustStkXref;
ORDER BY CustStockCode
*
DBSETPROP ("vlpsku", "View", "SendUpdates", .T.)
DBSETPROP("vlpsku" , "VIEW","WhereType",3)
*
DBSETPROP("vlpsku.Customer", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.Customer", "Field", "UpdateName", [ArCustStkXref.Customer])
DBSETPROP("vlpsku.Customer", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.CustStockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.CustStockCode", "Field", "UpdateName", [ArCustStkXref.CustStockCode])
DBSETPROP("vlpsku.CustStockCode", "Field", "KeyField", .T.)
*
DBSETPROP("vlpsku.StockCode", "Field", "Updatable", .T.)
DBSETPROP("vlpsku.StockCode", "Field", "UpdateName", [ArCustStkXref.StockCode])
DBSETPROP("vlpsku.StockCode", "Field", "KeyField", .F.)
*
SELECT 1
USE vlpsku
*
SELECT 2
USE lpsku INDEX stock
*
GO TOP
SCATTER MEMVAR
*
DO WHILE .NOT. EOF()
*
SELECT 1
*
INSERT INTO vlpsku (Customer, CustStockCode, StockCode);
VALUES("39050",m.ssku,m.StockCode)
*
IF NOT TABLEUPDATE(1, .t., [vlpsku])
AERROR(laError)
MessageBox([Can not Update vlpsku ]+laError[1,2])
EXIT
ENDIF
*
SELECT 2
*
IF .NOT. EOF()
SKIP
SCATTER MEMVAR
LOOP
ENDIF
*
ENDDO
*
CLOSE DATABASES ALL
*
RETURN