fbpx
Welcome, Guest
Username: Password: Remember me
Welcome to the XSharp forum!

Tell us and our members who you are, what you like and why you became a member of this site.
We welcome all new members and hope to see you around a lot!
  • Page:
  • 1

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #1

  • rn@warner-it.com
  • rn@warner-it.com's Avatar Topic Author
  • Offline
  • Posts: 11
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 )

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #2

What IS EPPreis in your table?

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #3

  • rn@warner-it.com
  • rn@warner-it.com's Avatar Topic Author
  • Offline
  • Posts: 11
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

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #4

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
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.

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #5

  • rn@warner-it.com
  • rn@warner-it.com's Avatar Topic Author
  • Offline
  • Posts: 11
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

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #6

  • rn@warner-it.com
  • rn@warner-it.com's Avatar Topic Author
  • Offline
  • Posts: 11
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

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #7

Which error? "an" is a bit vague ;)

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #8

  • rn@warner-it.com
  • rn@warner-it.com's Avatar Topic Author
  • Offline
  • Posts: 11
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

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #9

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

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

Access Table with Integer fields Price , Amount def as double Coversion problem 2 weeks 1 day ago #10

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
George, South Africa

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

Access Table with Integer fields Price , Amount def as double Coversion problem 1 week 6 days ago #11

Yes, as Johan said. It's much more efficient to get the value through "unboxing" compared to converting it to a string and then parsing that string back into a number again. The value of rdr["EPPreis"] is an Object(System.Double) (a System.Double stored in an object variable).

Another observation;
If you use string constants for your field, and table names you get a spell check at compile time, and you can also easily find all references to a particular field or table in your code.

/MathiasH

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

Last edit: by MathiasHakansson.
  • Page:
  • 1