My first experiment with CFront. I can read from a Navision 3.01b database using CFRONT (cfront.dll dated 8/7/2002) within C#. However, if I try to modify a record with the AssignField() function, I get a "type mismatch" error returned from mscorlib.dll. However, even doing explicit typecasting still generates the error....I can't see where I'm going wrong. Has anyone used CFront from within C# to write back to a Navision 3.01b (or 3.10) DB?
Here's a snippet of code I used behind a button on a Windows form(bombs on the AssignField() function):
int tablenum, rechandle,myfieldno;
object fData;
bool workedOK = false;
CFRONTLib._DCFRONT cf = new CFRONTLib.CFRONTClass();
cf.ConnectServer("MYSERVER","tcp");
tablenum = cf.TableNo("Event");
if (!cf.Login("me","you"))
MessageBox.Show("Bad Login");
cf.OpenCompany("MYCO");
if (!cf.OpenTable(ref tablenum,13) )
MessageBox.Show("Salesperson table could not be opened.");
rechandle = cf.AllocRec(tablenum);
cf.InitRec(tablenum,rechandle);
cf.BWT();
cf.AllowRecordNotFound();
cf.LockTable(tablenum,false);
if (cf.FindRec(tablenum,rechandle,"-") )
{ myfieldno = cf.FieldNo(tablenum,"Name");
fData = cf.GetFieldData(tablenum,rechandle,myfieldno)
fData = (object)"Anything";
try
{
cf.AssignField(tablenum,rechandle,myfieldno,ref fData);
}
catch(Exception ex)
{
MessageBox.Show("Error on AssignField is: " + ex.Message + "; Source: " + ex.Source);
}
try
{
workedOK = cf.ModifyRec(tablenum,rechandle);
}
catch(Exception ex)
{
MessageBox.Show("Error on ModifyRec is: " + ex.Message + "; Source: " + ex.Source);
}
cf.EWT();
cf.FreeRec(rechandle);
cf.CloseTable(tablenum);
cf.CloseCompany();
cf.CloseDatabase();
MessageBox.Show("Done!");
}
0
Comments
The problem ís the fieldnum which is supposed to be of type LONG.
Also when doing calcfields wich excpects an array of LONGs there is a problem.
So far I haven't found a solution, sorry. But I would be very interested in hearing from you if you get a breakthrough.
I have tried fooling around with but I can't make it work anyhow.
Also the same problem exists with VB.NET.
Thanks again!
I solve this problem with "proxy" ActiveX. In this ActiveX i have replaced all possibe 'Variant' usages.
CalcFields(Long,Long,Variant) was replaced with
CalcFlowFieldValue(hTable as Long,hRec as Long,FieldName As String).
All (almost) other methods was reimplemented or changed to normal data types (GetTextFieldValue, GetDecimalFieldValue , etc).
It helps me because old 'Variant' type is not fully incompatible with new 'object'.
My component written in VB6 and perfectly works in .NET Studio as reference (as pseudo-replacement of original CFRONT.OCX).
I can email it to you.
If it was hard to write, it should be hard to understand.
string fieldvalue = cf.GetFieldDataByName(hTable,hRecord,columnname).ToString();
I'm getting the error {"Object reference not set to an instance of an object." }.
Regards,
Hans de Graaf
I am trying get cfront working in c# .net only "i get a Object reference not set to an instance of an object" error
the dll imports (isnt there an easier way?)
the parser
Anyone know what the prob is?