xsharp.eu • Access Table with Integer fields Price , Amount def as double Coversion problem
Page 1 of 2

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:19 am
by rn@warner-it.com
Can someone please help me regarding this problem I am pasting the code in here
LOCAL cSelect,cSelectString := "" AS STRING
LOCAL cWhere AS STRING[]
LOCAL i, nLen AS INT
LOCAL cWhereClause := "" AS STRING
LOCAL cTemp AS STRING
LOCAL GridBackColor AS Color[]
LOCAL rdr AS OledbDataReader
LOCAL cStatement1 AS STRING
LOCAL cStatement2 AS STRING
LOCAL cmd AS OledbCommand
LOCAL dt AS DataTable
LOCAL AS400Lib AS STRING
LOCAL cTable,tablename,Table AS STRING
LOCAL cMenge AS STRING
LOCAL cPosPreis AS STRING
LOCAL cEPObj AS OBJECT
LOCAL cPosObj AS OBJECT



tablename := "OrdPos"

gSelect := "Select Pos,OrdPos,Artikel,Menge,Einheit,Kurztext,Postext,Preis,CreationDate From OrdPos where ServiceOrder = "+gServiceOrder+""


SELF:ds := Dataset{}
SELF:da := OledbDataAdapter{gSelect,oConn1}

cSelectString := gSelect
cmd := OledbCommand{cSelectString,oConn1}
*rdr := cmd:ExecuteReader(commandbehaviour.CloseConnection)
*rdr := cmd:connection.Open();
*dt:Load(rdr)
*oConn1:Open()
*dtZiel := dt:Clone()
*da:Update(dtZiel)

rdr := cmd:ExecuteReader()
cmd:CommandTimeout := 1 * 60 * 60
i := 0
DO WHILE rdr:Read()

*messagebox.show(gSelect)


gPos := rdr["Pos"]:Tostring()
gArtikel := rdr["Artikel"]:Tostring()
cMenge := rdr["Menge"]:ToString()
gEinheit := rdr["Einheit"]:ToString()
*gItemDesc := gItemDesc:replace("'", "")
*gOrdPos := rdr["OrdPos"]:Tostring()
gKurztext := rdr["Kurztext"]:ToString()
gPostext := rdr["Postext"]:ToString()

How can I get the FIELD EPPreis price defined AS double
IN the OrdPos Table converted to a string field or numeric field
without crashing AS an error. I am trying TO RECOVER it AS an OBJECT
also with problems.

cEPObj := rdr["EPPreis"]
IF cEPObj != NULL
gEKPreis := Convert.ToDouble(cEPObj)
ELSE
gEKPreis := 0
ENDIF
*cPosPreis := rdr["PosPreis"]:ToString()
Messagebox.show(gPos)
Messagebox.show(gArtikel)
Messagebox.show(gOrdPos)
Messagebox.show(gKurztext)
Messagebox.show(gPostext)
* messagebox.show(cMenge)
* messagebox.show(cEPPreis)
* messagebox.show(cPosPreis)
/*
messagebox.show(gArtikel) //:Replace("""","""""")

messagebox.show(gEinheit)
messagebox.show(gOrdPos)
messagebox.show(gPostext)
messagebox.show(gEPPreis)

*InsertFile()
*/
i++

// Call Close when done reading. , MORD,ItemNr, ItemDesc,New_ItemNr, .First_SerialNr, Warehouse, CurrentStatus, QTYIssued, QTYRequired, OperationNo, Releasedat
*rdr:close()
ENDDO

messageBox.show("Read End für ServiceOrder = " +gServiceOrder )

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:30 am
by FFF
What IS EPPreis in your table?

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:32 am
by rn@warner-it.com
Hi My name is Raymond Warner
I was first introduced to Vo a long time ago when I was working as an IT Manager for several Companies I then also worked a lot with Dieter Crispien here in Germnay who brought me further using Vo and then introducing me to Vulcan we did several Projects together . I also worked with John Parker on several projects. Anyway I have mo more contact with Dieter and was looking for the latest version of Vulcan and stumbled upon X#. Because I am familiar with the language and used Vulcan a lot I am now interested in doing my current Projects which I have started to programe in X#. I am a huge fan of VO and Vulcan and would like to carry on using X# as the next generation software I am also looking at Python/ Ironpython and have started small programes with Python and Ironpython an interface between X# and Python would be great.
I am happy to be a part of the X# Community

Best Regards
Raymond Warner

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:37 am
by robert
Raymond,
This should work for string conversions:

cEPObj := rdr["EPPreis"]:ToString()

And from the string you can then use this

LOCAL doubleValue as System.Double // you can also use REAL8
IF System.Double.TryParse(cEPObj, OUT doubleValue)

ENDIF

Robert

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:41 am
by rn@warner-it.com
EPPreis is a field in the Ordpos Table it means position price for an item
EKPreis is buying price
Epospreis is the total postionprice
They are defined as double and 2 decimal positions

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:52 am
by rn@warner-it.com
Hi Robert,
Sorry for the delay I was checking out what you told me to do.
Robert my field is a Double in the Access table
I want to convert it when I use the rdr to the field to string I then get an error
cEPPreis := rdr["EPPreis"]:ToString()
EPPreis is a field defined as string EPPreis is a field defined as aDouble in the access table

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 8:55 am
by FFF
Which error? "an" is a bit vague ;)

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 9:04 am
by rn@warner-it.com
Hi Robert,
I made a big mistake the fields are missing in the select stastement sorry for the bother How do I close this
Again very sorry foir my mistake.

Raymond

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 9:14 am
by lumberjack
Hi Raymond,
Welcome I see you already seeing how quick and willing people are to assist.
rn@warner-it.com wrote:Can someone please help me regarding this problem I am pasting the code in here
The easiest if you know the type of your Field in the database table is:

Code: Select all

LOCAL dEPPreis AS Real8
rdr := cmd:ExecuteReader()    
DO WHILE rdr:Read()
...
  dEPPreis :=  (Real8)rdr["EPPreis"]   
If you know the type of the object you can cast it with the syntax:

Code: Select all

(TypeToCastTo)obj

Access Table with Integer fields Price , Amount def as double Coversion problem

Posted: Sat Mar 09, 2019 9:17 am
by lumberjack
Raymond,
rn@warner-it.com wrote:Hi Robert,
I made a big mistake the fields are missing in the select stastement sorry for the bother How do I close this
Again very sorry for my mistake.
Don't be sorry, we all human, we all make (programming)mistakes.
Glad you got it sorted!
Keep in touch on the forums,