A similar thread already exists: thread631-526541
In fact, I am the person who works on changing the code made by Dave to .Net.
Now, I have a question. I translated the code in that thread to C#, and this is what I got:
object oArray;
AccpacCOMAPI.AccpacView[] arArray;
AccpacCOMAPI.AccpacView CPTIMECARD1header = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1headerFields;
mDBLinkCmpRW.OpenView("CP0031", out CPTIMECARD1header);
CPTIMECARD1headerFields = CPTIMECARD1header.Fields;
// ##
AccpacCOMAPI.AccpacView CPTIMECARD1detail = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1detailFields;
mDBLinkCmpRW.OpenView("CP0032", out CPTIMECARD1detail);
CPTIMECARD1detailFields = CPTIMECARD1detail.Fields;
// ##
// added
arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1detail };
oArray = arArray;
CPTIMECARD1header.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1header };
oArray = arArray;
CPTIMECARD1detail.Compose(ref oArray);
AccpacCOMAPI.AccpacView CPEMASTER3header = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3headerFields;
mDBLinkCmpRW.OpenView("CP0014", out CPEMASTER3header);
CPEMASTER3headerFields = CPEMASTER3header.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail1 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail1Fields;
mDBLinkCmpRW.OpenView("CP0008", out CPEMASTER3detail1);
CPEMASTER3detail1Fields = CPEMASTER3detail1.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail2 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail2Fields;
mDBLinkCmpRW.OpenView("CP0010", out CPEMASTER3detail2);
CPEMASTER3detail2Fields = CPEMASTER3detail2.Fields;
AccpacCOMAPI.AccpacView CPEMASTER3detail3 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail3Fields;
mDBLinkCmpRW.OpenView("CP0053", out CPEMASTER3detail3);
CPEMASTER3detail3Fields = CPEMASTER3detail3.Fields;
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3detail1, CPEMASTER3detail2, CPEMASTER3detail3 };
oArray = arArray;
CPEMASTER3header.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail1.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header, null };
oArray = arArray;
CPEMASTER3detail2.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail3.Compose(ref oArray);
// begins insert
CPTIMECARD1detail.Init();
object oValue = (object)"1";
CPTIMECARD1detailFields.get_FieldByName("ENTRYTYPE").set_Value(ref oValue); // Entry Type
// employee start
CPTIMECARD1detail.Order = 0;
oValue = (object)EmployeeID;
// FAILS HERE:------\/\/
CPTIMECARD1headerFields.get_FieldByName("EMPLOYEE").set_Value(ref oValue); // Employee
oValue = (object)timecard;
CPTIMECARD1headerFields.get_FieldByName("TIMECARD").set_Value(ref oValue);
oValue = (object)PeriodEnd;
CPTIMECARD1headerFields.get_FieldByName("PEREND").set_Value(ref oValue); // Period end date
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;
for (int i = 0; i <= ChargeType.Length; i++)
{
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Init();
oValue = (object)ChargeType;
CPTIMECARD1detailFields.get_FieldByName("EARNDED").PutWithoutVerification(ref oValue); // Earnings/Deduction
oValue = (object)Amount;
CPTIMECARD1detailFields.get_FieldByName("RATE").set_Value(ref oValue); // E/D/Tax Rate/Amt/Percent
CPTIMECARD1detail.Insert();
}
CPTIMECARD1detail.Order = 0;
CPTIMECARD1header.Insert();
CPTIMECARD1header.Read();
// employee ends
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;
}
the place where it fails is marked. There is no error messahe or anthing, is simply crashes (well, OK, it sayd something like "..the COM component returned the error message: E_FAIL...", which obviously doesn not help.
Could someone point out any errors I have in my code?
Thanks a bunch.
In fact, I am the person who works on changing the code made by Dave to .Net.
Now, I have a question. I translated the code in that thread to C#, and this is what I got:
object oArray;
AccpacCOMAPI.AccpacView[] arArray;
AccpacCOMAPI.AccpacView CPTIMECARD1header = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1headerFields;
mDBLinkCmpRW.OpenView("CP0031", out CPTIMECARD1header);
CPTIMECARD1headerFields = CPTIMECARD1header.Fields;
// ##
AccpacCOMAPI.AccpacView CPTIMECARD1detail = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1detailFields;
mDBLinkCmpRW.OpenView("CP0032", out CPTIMECARD1detail);
CPTIMECARD1detailFields = CPTIMECARD1detail.Fields;
// ##
// added
arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1detail };
oArray = arArray;
CPTIMECARD1header.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1header };
oArray = arArray;
CPTIMECARD1detail.Compose(ref oArray);
AccpacCOMAPI.AccpacView CPEMASTER3header = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3headerFields;
mDBLinkCmpRW.OpenView("CP0014", out CPEMASTER3header);
CPEMASTER3headerFields = CPEMASTER3header.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail1 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail1Fields;
mDBLinkCmpRW.OpenView("CP0008", out CPEMASTER3detail1);
CPEMASTER3detail1Fields = CPEMASTER3detail1.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail2 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail2Fields;
mDBLinkCmpRW.OpenView("CP0010", out CPEMASTER3detail2);
CPEMASTER3detail2Fields = CPEMASTER3detail2.Fields;
AccpacCOMAPI.AccpacView CPEMASTER3detail3 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail3Fields;
mDBLinkCmpRW.OpenView("CP0053", out CPEMASTER3detail3);
CPEMASTER3detail3Fields = CPEMASTER3detail3.Fields;
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3detail1, CPEMASTER3detail2, CPEMASTER3detail3 };
oArray = arArray;
CPEMASTER3header.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail1.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header, null };
oArray = arArray;
CPEMASTER3detail2.Compose(ref oArray);
arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail3.Compose(ref oArray);
// begins insert
CPTIMECARD1detail.Init();
object oValue = (object)"1";
CPTIMECARD1detailFields.get_FieldByName("ENTRYTYPE").set_Value(ref oValue); // Entry Type
// employee start
CPTIMECARD1detail.Order = 0;
oValue = (object)EmployeeID;
// FAILS HERE:------\/\/
CPTIMECARD1headerFields.get_FieldByName("EMPLOYEE").set_Value(ref oValue); // Employee
oValue = (object)timecard;
CPTIMECARD1headerFields.get_FieldByName("TIMECARD").set_Value(ref oValue);
oValue = (object)PeriodEnd;
CPTIMECARD1headerFields.get_FieldByName("PEREND").set_Value(ref oValue); // Period end date
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;
for (int i = 0; i <= ChargeType.Length; i++)
{
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Init();
oValue = (object)ChargeType;
CPTIMECARD1detailFields.get_FieldByName("EARNDED").PutWithoutVerification(ref oValue); // Earnings/Deduction
oValue = (object)Amount;
CPTIMECARD1detailFields.get_FieldByName("RATE").set_Value(ref oValue); // E/D/Tax Rate/Amt/Percent
CPTIMECARD1detail.Insert();
}
CPTIMECARD1detail.Order = 0;
CPTIMECARD1header.Insert();
CPTIMECARD1header.Read();
// employee ends
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;
}
the place where it fails is marked. There is no error messahe or anthing, is simply crashes (well, OK, it sayd something like "..the COM component returned the error message: E_FAIL...", which obviously doesn not help.
Could someone point out any errors I have in my code?
Thanks a bunch.