I have code that takes a file from a folder, and attaches it to a receipt header. It was working just fine, but then I got the above error for every file I try to save now. It won’t work anymore! Here is my code:
try{
//Creates a record attached to the part#
ReceiptAdapter adapterReceipt = new ReceiptAdapter(this.oTrans);
adapterReceipt.BOConnect();
POAdapter adapterPO = new POAdapter(this.oTrans);
adapterPO.BOConnect();
string PONum = po;
string PackNum = pack;
adapterPO.GetByID(Convert.ToInt32(po));
EpiDataView edvPA2 = new EpiDataView();
edvPA2.dataView = new DataView(adapterPO.POData.POHeader);
int vend = Convert.ToInt32(edvPA2.dataView[edvPA2.Row]["VendorNum"]);
string purch = Convert.ToString(edvPA2.dataView[edvPA2.Row]["PurPoint"]);
try
{
adapterReceipt.GetNewRcvHeadAttch(vend,purch,pack);
} catch (System.Exception ex)
{
errorlog("NewAttchR() " + newfile,ex.ToString());
MessageBox.Show(Convert.ToString(ex));
return;
}
DataRow newXAttchRow = adapterReceipt.ReceiptData.RcvHeadAttch[adapterReceipt.ReceiptData.RcvHeadAttch.Rows.Count - 1];
newXAttchRow["Company"] = "NET";
newXAttchRow["FileName"] = newfile;
newXAttchRow["DrawDesc"] = Desc;
newXAttchRow["DocTypeID"] ="PACK";
adapterReceipt.Update();
adapterPO.Dispose();
adapterReceipt.Dispose();
oTrans.Update();
oTrans.Refresh();
All the variables are provided from a different function. PurPoint is always an empty value, but everything else exists as a record in Epicor. Here is the error I get for a document I am trying to save:
System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Table: RcvHeadAttch
Company=‘NET’ VendorNum=‘356’ PurPoint=’’ PackSlip=‘874220’ DrawingSeq=‘0’ SysRowID=‘00000000-0000-0000-0000-000000000000’: ForeignKeyConstraint RcvHeadToRcvHeadAttch requires the child key values (NET, 356, , 874220) to exist in the parent table. —> System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at Ice.DatasetAdapter.CopyTSTableToDataTable[TIceRow,TDataTable](IceTable1 sourceTSTable, TDataTable destinationTable) --- End of inner exception stack trace --- at Ice.DatasetAdapter.CopyTSTableToDataTable[TIceRow,TDataTable](IceTable
1 sourceTSTable, TDataTable destinationTable)
at Erp.Proxy.BO.ReceiptImpl.GetNewRcvHeadAttch(ReceiptDataSet ds, Int32 vendorNum, String purPoint, String packSlip)
at Erp.Adapters.ReceiptAdapter.GetNewRcvHeadAttch(Int32 vendorNum, String purPoint, String packSlip)
at Script.NewAttchR(String newfile, String Desc, String po, String pack)