xsharp.eu • Convert Object -> Numeric
Page 1 of 2

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 12:39 pm
by Frank Müßner
Hallo zusammen,
ich stelle mal die Frage im deutschen Forum, liegt mir einfach besser.
Ich erstelle eine Abfrage an einen PG Server, ein einfaches Select und bekomme bei Numeric Feldern ein Object zurück vom Type System.Decimal.

Local nValue as usual

npgresult:=NpgCom:ExecuteScalar()
if Upper(npgresult:GetType():Tostring())="SYSTEM.DECIMAL"
nValue:=npgresult:Value ->> Error
endif

Bekomme ich diese Meldung:

Vulcan.NET Runtime Error

Error Code: 16 [No exported variable]
Subsystem: BASE
Description: No exported variable
Function: IVARGET
Argument 2: cName
Argument(s):
1: "Value" (STRING)
Call Stack:
bei VulcanRTFuncs.Functions.$LateBinding$__IVarGet(Object oObject, String cName, Boolean isSelf)
bei VulcanRTFuncs.Functions.IVarGet(Object oObject, String sInstanceVar)
bei AuftragSQLKasse.Exe.Functions.GetOnesqlresult(__Usual[] Xs$Args) in F:VSVisual Studio 2017WinQuickSqlKasseAuftragSQLKasseSql.prg:Zeile 633.

Ich sehe aber im Debugger das Value mit dem eigentlichen Wert vorhanden ist.
Ich finde keine Konvertierung für den Wert.

Hat jemand einen Hinweis?

Frank

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 1:05 pm
by wriedmann
Hallo Frank,

ich habe es nicht probiert, aber in der Klasse System.Convert sollte es passende Methode geben.

Decimal ist zwar ein toller Datentyp, aber in der Vulcan Runtime wahrscheinlich stiefmütterlich behandelt. Ich würde mal versuchen, das in ein real8 zu konvertieren, mit System.Convert.ToDouble() sollte das gehen.

lg

Wolfgang

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 1:08 pm
by Meinhard
Hi Frank,

nValue:=Convert.ToDouble(npgresult:Value)

sollte helfen.
Das Problem ist m.E., dass der Datentyp in den Vulcan Usuals nicht implementiert ist => auf X# Runtime umstellen, da gibt es das Problem nicht.

Regards
Meinhard

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 1:52 pm
by Frank Müßner
Hallo ihr beiden,

leider bringt das nicht das gewünschte Ergebnis.

nValue:=System.Convert.ToDouble(npgresult:Value)
oder auch
nValue:=System.Convert.ToDouble(npgresult)

bringen beide diese Fehlermeldung:

XS0121 The call is ambiguous between the following methods or properties: 'System.Convert.ToDouble(int)' and 'System.Convert.ToDouble(string)'

@Meinhard,
ich würde gern mit der X# Runtime den Transport vornehmen, leider habe ich es nicht geschafft VN2ADO mit der X# Runtime zu compilieren. Nur deshalb habe ich die Vulcan Runtime derzeit.
Kann es eine Compiler Einstellung sein?

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 3:37 pm
by Karl-Heinz
Frank Müßner wrote:
leider bringt das nicht das gewünschte Ergebnis.

nValue:=System.Convert.ToDouble(npgresult:Value)
oder auch
nValue:=System.Convert.ToDouble(npgresult)

bringen beide diese Fehlermeldung:

XS0121 The call is ambiguous between the following methods or properties: 'System.Convert.ToDouble(int)' and 'System.Convert.ToDouble(string)'
Hallo Frank,

probier´s mal mit changeType()

? (DOUBLE) System.Convert.changeType ( npgresult , typeof(DOUBLE) )

Gruß
Karl-Heinz

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 3:43 pm
by Frank Müßner
Hallo Karl-Heinz,

super für die Hilfe, damit klappt es. Auf diese Konstellation wäre ich nie gekommen :-( Danke.
Jetzt geht es weiter eine kleine App zu Transportieren.

Nebenbei, schon jemand VN2ADO mit X# compiliert?

GRüße
und schönes WE
Frank

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 7:17 pm
by lumberjack
Hi Frank,
Frank Müßner wrote:Hallo zusammen,
Local nValue as usual
npgresult:=NpgCom:ExecuteScalar()
if Upper(npgresult:GetType():Tostring())="SYSTEM.DECIMAL"
nValue:=npgresult:Value ->> Error
endif
Execute scalar will return the first column of the first row of your query. What is the command text of this statement?

Why use a usual? Your query might need to use ExecuteNonQuery actually since that will return nothing.

CREATE/ALTER/DROP need to use NonQuery

INSERT/UPDATE/DELETE you might use ExecuteScalar to return the number of rows affected.

ExecuteScalar could be used with something like "SELECT count(*) FROM table", otherwise you need to use a DataReader.

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 8:24 pm
by Frank Müßner
Hi Johann,

yes of course for that i use ExecuteScalar.

I get something from this select "Select field from table where zeile=1"
So i can get Strings, or dates but when have numeric values, i get a System.Decimal back.
But this i have to convert to a VO Numeric. That was the Problem, not the Select. :-)

Frank

Convert Object -> Numeric

Posted: Fri Mar 01, 2019 10:26 pm
by lumberjack
Frank Müßner wrote: yes of course for that i use ExecuteScalar.
I get something from this select "Select field from table where zeile=1"
So i can get Strings, or dates but when have numeric values, i get a System.Decimal back.
Ok I understand, why still VO usual?
PS: My German is improving... :)

Convert Object -> Numeric

Posted: Sat Mar 02, 2019 7:32 am
by lumberjack
Hi Frank,
Ignore what I have said previously.
Frank Müßner wrote: Local nValue as usual
npgresult:=NpgCom:ExecuteScalar()
if Upper(npgresult:GetType():Tostring())="SYSTEM.DECIMAL"
nValue:=npgresult:Value ->> Error
endif
Try this:

Code: Select all

Local nValue as usual
Local npgresult as object // ExecuteScalar returns an object
npgresult:=NpgCom:ExecuteScalar()
if npgresult:GetType() = typeOf(System.Decimal)
     nValue:= (int)npgresult // No need to try with Value property.
endif
HTH,