Error : Violation of PRIMARY KEY constraint 'PKAAG20000'. Cannot insert duplicate key in object 'dbo.AAG20000'. The duplicate key value is (357112).
why? and how fix error ??
used Code :
{
string connectionStringGP = @/Data Source=.;Initial Catalog=test ;persist security info=False;/;
using (eConnectMethods eConnect = new eConnectMethods())
{
eConnectType eConnectTypeSalesTransaction = new eConnectType();
eConnectOut eConnectOut1 = new eConnectOut()
{
DOCTYPE = /Sales_Transaction/, // Specify the type of document you want to retrieve
OUTPUTTYPE = 2, // Specify output type: 2 for XML
INDEX1FROM =/CON/2300034/ , ///CON/2400006/ // Specify the start index
INDEX1TO =/CON/2300034/ ,// /CON/2400006/// Specify the end index
FORLIST = 1, // Specify 1 to retrieve a list
eConnectTypeSalesTransaction.RQeConnectOutType = new RQeConnectOutType[] { new RQeConnectOutType() { eConnectOut = eConnectOut1 } };
string xmlSopTransaction = SerializeObject(eConnectTypeSalesTransaction);
//Call the GetEntity method to retrieve data
string response = eConnect.GetEntity(connectionStringGP, xmlSopTransaction);
//Console.WriteLine($///r/Data retrieved First :/{response} //r/ ________________________________________________/);
// Deserialize the XML string into objects
Root root = DeserializeFromXml<Root>(response);
#region Update Sales Transaction
taSopHdrIvcInsert sopHdrIvc = new taSopHdrIvcInsert();
sopHdrIvc.SOPNUMBE = root.EConnect.SOTrans.SOPNUMBE;
sopHdrIvc.SOPTYPE = root.EConnect.SOTrans.SOPTYPE;
sopHdrIvc.DOCID = root.EConnect.SOTrans.DOCID;
sopHdrIvc.CUSTNMBR = root.EConnect.SOTrans.CUSTNMBR;
sopHdrIvc.DOCDATE = root.EConnect.SOTrans.DOCDATE;
sopHdrIvc.BACHNUMB = root.EConnect.SOTrans.BACHNUMB;
taSopLineIvcInsert_ItemsTaSopLineIvcInsert sopLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
sopLine.SOPTYPE = root.EConnect.SOTrans.Lines[0].SOPTYPE;
sopLine.CUSTNMBR = root.EConnect.SOTrans.CUSTNMBR;
sopLine.QUANTITY = 9; //9root.EConnect.SOTrans.Lines[0].QUANTITY;
sopLine.DOCDATE = root.EConnect.SOTrans.DOCDATE;
sopLine.ITEMNMBR = root.EConnect.SOTrans.Lines[0].ITEMNMBR;
sopLine.SOPNUMBE = root.EConnect.SOTrans.Lines[0].SOPNUMBE;
sopLine.LNITMSEQ = root.EConnect.SOTrans.Lines[0].LNITMSEQ;
sopLine.LOCNCODE = root.EConnect.SOTrans.Lines[0].LOCNCODE;
updateSOPTransactionType.SOPTransactionType = new SOPTransactionType[]
{
new SOPTransactionType()
{
taSopHdrIvcInsert = sopHdrIvc,
taSopLineIvcInsert_Items = sopLines,
}
};
#endregion
var updatedResponse = eConnect.UpdateTransactionEntity(connectionStringGP, updatedXmlString);
//var updatedResponse = eConnect.DeleteTransactionEntity(connectionStringGP, updatedXmlString);
string response2 = eConnect.GetEntity(connectionStringGP, xmlSopTransaction);
Console.WriteLine($///r/Data retrieved After :/{response2} //r/ _______________________________/);
}
catch (Exception ex)
{
Console.WriteLine(/Error: / + ex.Message);
}