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

We encourage new members to introduce themselves here. Get to know one another and share your interests.
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

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

Post 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 )
FFF
Posts: 1532
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

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

Post by FFF »

What IS EPPreis in your table?
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

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

Post 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
User avatar
robert
Posts: 4258
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

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

Post 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
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

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

Post 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
FFF
Posts: 1532
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

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

Post by FFF »

Which error? "an" is a bit vague ;)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

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

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

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

Post 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
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

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

Post 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,
______________________
Johan Nel
Boshof, South Africa
Post Reply