Convert Object -> Numeric

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

Frank Müßner
Posts: 276
Joined: Sat Dec 12, 2015 2:22 pm
Location: Germany

Convert Object -> Numeric

Post 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
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Convert Object -> Numeric

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Meinhard
Posts: 81
Joined: Thu Oct 01, 2015 4:51 pm

Convert Object -> Numeric

Post 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
Frank Müßner
Posts: 276
Joined: Sat Dec 12, 2015 2:22 pm
Location: Germany

Convert Object -> Numeric

Post 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?
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am

Convert Object -> Numeric

Post 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
Frank Müßner
Posts: 276
Joined: Sat Dec 12, 2015 2:22 pm
Location: Germany

Convert Object -> Numeric

Post 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
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Convert Object -> Numeric

Post 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.
Frank Müßner
Posts: 276
Joined: Sat Dec 12, 2015 2:22 pm
Location: Germany

Convert Object -> Numeric

Post 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
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Convert Object -> Numeric

Post 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... :)
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Convert Object -> Numeric

Post 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,
Post Reply