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 09 Mar 2019 09:19 #7586

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 46
  • 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 09 Mar 2019 09:30 #7587

  • FFF's Avatar

  • FFF


  • Posts: 976
  • What IS EPPreis in your table?
    Regards
    Karl (X# 2.5b; Xide 1.25; W8.1/64 German)

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

    Access Table with Integer fields Price , Amount def as double Coversion problem 09 Mar 2019 09:32 #7588

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 46
  • 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 09 Mar 2019 09:37 #7589

  • robert's Avatar

  • robert


  • Posts: 1793
  • 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

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

    Access Table with Integer fields Price , Amount def as double Coversion problem 09 Mar 2019 09:41 #7590

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 46
  • 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 09 Mar 2019 09:52 #7592

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 46
  • 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 09 Mar 2019 09:55 #7593

  • FFF's Avatar

  • FFF


  • Posts: 976
  • Which error? "an" is a bit vague ;)
    Regards
    Karl (X# 2.5b; Xide 1.25; W8.1/64 German)

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

    Access Table with Integer fields Price , Amount def as double Coversion problem 09 Mar 2019 10:04 #7594

  • rn@warner-it.com's Avatar


  • Topic Author


  • Posts: 46
  • 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 09 Mar 2019 10:14 #7595

  • lumberjack's Avatar

  • lumberjack


  • Posts: 687
  • Hi Raymond,
    Welcome I see you already seeing how quick and willing people are to assist.

    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 09 Mar 2019 10:17 #7596

  • lumberjack's Avatar

  • lumberjack


  • Posts: 687
  • Raymond,

    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 11 Mar 2019 10:34 #7651

  • MathiasHakansson's Avatar

  • MathiasHakansson


  • Posts: 50
  • 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