fbpx
Welcome, Guest
Username: Password: Remember me
Hier wird Deutsch gesprochen
  • Page:
  • 1

TOPIC: Convert Object -> Numeric

Convert Object -> Numeric 2 months 3 weeks ago #7457

  Frank Müßner's Avatar Topic Author Frank Müßner Offline Posts: 83
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:\VS\Visual Studio 2017\WinQuick\SqlKasse\AuftragSQLKasse\Sql.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

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7458

  wriedmann's Avatar wriedmann Offline Posts: 1515
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7459

  Meinhard's Avatar Meinhard Offline Posts: 40
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

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7460

  Frank Müßner's Avatar Topic Author Frank Müßner Offline Posts: 83
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?

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7461

  Karl-Heinz's Avatar Karl-Heinz Offline Posts: 236

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

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7462

  Frank Müßner's Avatar Topic Author Frank Müßner Offline Posts: 83
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

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7468

  lumberjack's Avatar lumberjack Offline Posts: 416
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.
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7469

  Frank Müßner's Avatar Topic Author Frank Müßner Offline Posts: 83
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

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7470

  lumberjack's Avatar lumberjack Offline Posts: 416

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... :)
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7471

  lumberjack's Avatar lumberjack Offline Posts: 416
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:
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,
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Convert Object -> Numeric 2 months 3 weeks ago #7472

  robert's Avatar robert Offline Posts: 947
I would write
if npgresult IS Decimal
     nValue:= (int)npgresult // No need to try with Value property.
endif
Robert

PS In the next build you can also use the IS pattern
IF npgResult is Decimal dValue
   // now there is a local dValue of type Decimal with the value from npgResult
  nValue := (INT) dValue   // the compiler now knows that you are converting a decimal to an int
endif
Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Last edit: by robert. Reason: formatting

Convert Object -> Numeric 2 months 3 weeks ago #7473

  Frank Müßner's Avatar Topic Author Frank Müßner Offline Posts: 83
Hi Johann;

lumberjack wrote: Ok I understand, why still VO usual?
PS: My German is improving... :)


because i don´t know what i am getting from the select. :-(

Historie:
In VO Code, i use (VO2ADO) Adoserver to get one Value from a Table. Then i get with AdoServer:RecordSet:Fields:Item(1):Type, the Type of the Column an can handle and modify this.

When Transport to X# i try to replace this with .Net Postgresql Provide, only for this type of getting one Value from Table.
and there comes the Problem with getting the right DataType. Sample, Decimals come as Object.

But i have with Karl-Heinz code solve this.



@ Robert,

if npgresult IS Decimal
nValue:= (int)npgresult // No need to try with Value property.
endif


not work, because npgresult is Object. when get Numeric Values from PG.

But i have now solved the Problem with Karl-Heinz Code.
Perhaps some not work, because i have VN3 Runtime.
I wait for VX2ADO and then use the X# Runtime, and try to transport my main App. :-)
Regards, Frank

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: wriedmann