I am currently struggling with the new CFrontDotNet assembly in VB.Net. I cannot cast the NavisionValue type returned from GetFieldData to the correct DataType. It works perfectly OK in C#. See following examples for more details.
In C#
----
NavisionInteger i;
NavisionValue v;
v = coreApi.GetFieldData(tblHnd, rcdHnd, 1);
i = v //This works in C#
----
And then in VB I write
----
Dim I As NavisionInteger
Dim V As NavisionValue
Dim O As Object
V = CoreApi.GetFieldData(TblHnd, RcdHnd, 1);
I = V 'Does not compile, cannot cast
I = CType(V, NavisionInteger) 'Does not compile, cannot cast
O = V 'Works
I = CType(O, NavisionInteger) 'Runtime exception, invalid cast
----
I am assuming I have missed something blindingly obvious but I have run so far down a dark alley I cannot see it. Any help will be greatly appreceated. Allthough I have written a C# utility to solve this problem most of the others guys prefer VB and life will be easier if I can solve this problem.
Many thanks
0
Comments
Try to use Navision 4.0 sp2 - it has corrections.
I use code:
Dim dgv As New DataGridView
Dim cfv As Microsoft.Navision.CFront.NavisionValue
Dim thand As Integer
Dim rhand As Integer
NField = cf.NextField(thand, OField)
cfv = cf.GetFieldData(thand, rhand, NField)
Select Case cf.FieldType(thand, NField)
Case Microsoft.Navision.CFront.NavisionFieldType.BigInteger
Dim navtype As Microsoft.Navision.CFront.NavisionBigInteger
navtype = cfv
dgv.Item(i, j).Value = navtype.Value.ToString()
Case Microsoft.Navision.CFront.NavisionFieldType.Binary
dgv.Item(i, j).Value = "*"
Case Microsoft.Navision.CFront.NavisionFieldType.Blob
dgv.Item(i, j).Value = "*"
Case Microsoft.Navision.CFront.NavisionFieldType.Boolean
Dim navtype As Microsoft.Navision.CFront.NavisionBoolean
navtype = cfv
dgv.Item(i, j).Value = navtype.Value.ToString()
.....
It works on my computer.
I'm not sure but suggest update client to SP2 too. CFront uses objects from Nav directory so it must be the same versions.
Any one can help me out ?
Thanks
Did you tried contruction like me?
I can only say: it works on my computer. I can give you example code if you want and say "how"
:-s
I tried it in C#, and it works fine.
It's weird.
So i can't help you as it works for me. I can only propose do reseach.
Do you have error on some types of fields or on all types?
There were error in some NavisionValue types, but it was corrected.
Are you sure you use latest cfront and there are no another cfront dll installed?
Prt of my code:
Dim cfv As Microsoft.Navision.CFront.NavisionValue
Dim thand As Integer
Dim rhand As Integer
thand = cf.OpenTable(tno)
rhand = cf.AllocRecord(thand)
If cf.FindRecord(thand, rhand, "-") Then
If cf.RecordCount(thand) < 50 Then
trec = cf.RecordCount(thand)
Else
trec = 50
End If
dgv.RowCount = trec
For j = 0 To trec - 1
OField = 0
For i = 0 To cf.FieldCount(thand) - 1
NField = cf.NextField(thand, OField)
cfv = cf.GetFieldData(thand, rhand, NField)
Select Case cf.FieldType(thand, NField)
Case Microsoft.Navision.CFront.NavisionFieldType.BigInteger
Dim navtype As Microsoft.Navision.CFront.NavisionBigInteger
navtype = cfv
dgv.Item(i, j).Value = navtype.Value.ToString()
Case Microsoft.Navision.CFront.NavisionFieldType.Binary
dgv.Item(i, j).Value = "*"
Case Microsoft.Navision.CFront.NavisionFieldType.Blob
dgv.Item(i, j).Value = "*"
Case Microsoft.Navision.CFront.NavisionFieldType.Boolean
Dim navtype As Microsoft.Navision.CFront.NavisionBoolean
navtype = cfv
dgv.Item(i, j).Value = navtype.Value.ToString()
Case Microsoft.Navision.CFront.NavisionFieldType.Code
Dim navtype As Microsoft.Navision.CFront.NavisionCode
navtype = cfv
dgv.Item(i, j).Value = navtype.ToString
Case Microsoft.Navision.CFront.NavisionFieldType.Date
Dim navtype As Microsoft.Navision.CFront.NavisionDate
navtype = cfv
'dgv.Item(i, j).Value = navtype.Value.ToUniversalTime
dgv.Item(i, j).Value = "?Date-Bug?"
Case Microsoft.Navision.CFront.NavisionFieldType.DateFormula
Dim navtype As Microsoft.Navision.CFront.NavisionDateFormula
navtype = cfv
dgv.Item(i, j).Value = navtype.Value.ToString()
.....
Another idea: maybe it is Visual studio or .net problems?
#-o