Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How do I update a currency field?

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    How do I update a currency field?

    Hi,

    I have a field in my database that is 'Currency'. Now in delphi I have this code:

    Code:
    Qryupdatestock.SQL.Clear;
    Qryupdatestock.SQL.Add('Update Z1Read');
    Qryupdatestock.SQL.Add('Set '+ Category + ' = '+Category+ '+ ' +FloattoStr(Price));
    Qryupdatestock.SQL.Add('Where Dates = '+DatetoStr(Date));
    Qryupdatestock.execsql;
    And example of FloattoStr(Price) = 2.4 for example

    Now, I try this, but it doesn't work. I want it to 'add' onto what is already there. It runs fine, but it doesn't update the database. I am assuming that the format is entered incorrectly

    Any help appreciated

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How do I update a currency field?

    What database type is this and table structure?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do I update a currency field?

    Um...what do you mean by database type? I am using Microsoft Access if it answers your question , and table structure.... I'm not sure, I have got a picture though:



    Thanks

  5. #4
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do I update a currency field?

    i have done some testing and I have realised that it is not the currency which is the problem, it is the 'Dates'
    Code:
    Qryupdatestock.SQL.Clear;
    Qryupdatestock.SQL.Add('Update Z1Read');
    Qryupdatestock.SQL.Add('Set '+ Category + ' = '+Category+ '+ ' +FloattoStr(Price));
    Qryupdatestock.SQL.Add('Where Dates = '+DatetoStr(Date));
    Qryupdatestock.execsql;
    If I get rid of the 'Where Dates = '+DatetoStr(Date) , it works, ie it updates the whole Books column. If I replace the Where Dates with Where Something_Else, it also works. So basically, my Date Format is wrong.... how comes?

    Thanks

    PS: Right, I think I have got a clue for you guys to help solve this issue:



    Basically, it doesn't actually add what you type into SQL, it adds some weird time format. Thank you! The end is in sight

  6. #5
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How do I update a currency field?

    Try wrapping your date value in single quotes.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #6
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do I update a currency field?

    Code:
    UPDATE Z1Read
    Set Books = 10
    Where Dates = '21/03/2010'
    If I have that, it doesn't work, it gives me a 'Data Mismatch' error.

    Whereas if I had this:

    Code:
    UPDATE Z1Read
    Set Dates = '21/03/2010'
    Where Books = 10
    It does work. Any ideas? The thing is, I need the first one.

  8. #7
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How do I update a currency field?

    It looks like you need to use # to delimit your date strings. Access Tips: Query and Filter Criteria
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #8
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do I update a currency field?

    You are a legend THANKS!!

  10. #9
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How do I update a currency field?

    Nah, I'm just good at Googling.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  11. #10
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do I update a currency field?

    WHY? It works, but now its doing something stupid, Look:

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    with AdoQuery1 do
    begin
    SQL.Clear;
    SQL.Add('Insert into Table1');
    Sql.Add('(Dates)');
    Sql.Add('Values') ;
    sql.Add('(#' + DatetoStr(Date) + '#);' );
    ExecSql;
    Showmessage(DatetoStr(Date));
    end;
    end;
    This is just one form with one button which executes this code



    But look what it inserts!



    It inserts 4/3/2010 rather than 3/4/2010
    It's either doing it in an american format, or its just wrong....

    I havent touched my program.....

    Any help?

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MySQL Update, gives no error or update
    By bbqroast in forum PHP Development
    Replies: 5
    Last Post: 07-19-2011, 05:17 AM
  2. update mysql field on a certain time
    By arxh in forum PHP Development
    Replies: 7
    Last Post: 08-05-2010, 04:03 PM
  3. Problem with UPDATE a field in the mySQL table
    By Thevenin in forum PHP Development
    Replies: 7
    Last Post: 04-27-2010, 09:16 AM
  4. Update command tries to update the wrong table...
    By Shaddix in forum Visual Basic Programming
    Replies: 0
    Last Post: 01-08-2010, 08:18 AM
  5. Update database field
    By jashsayani in forum Visual Basic Programming
    Replies: 1
    Last Post: 09-21-2009, 05:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts