Jump to content

How do I update a currency field?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Hi,

I have a field in my database that is 'Currency'. Now in delphi I have this 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
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What database type is this and table structure?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
2710

2710

    Programmer

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

Posted Image

Thanks

#4
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
i have done some testing and I have realised that it is not the currency which is the problem, it is the 'Dates'
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:

Posted Image

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

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Try wrapping your date value in single quotes.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
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:

UPDATE Z1Read
Set Dates = '21/03/2010'
Where Books = 10

It does work. Any ideas? The thing is, I need the first one.

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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

#8
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
You are a legend :D THANKS!! :D

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

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

#10
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
WHY? It works, but now its doing something stupid, Look:

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

Posted Image

But look what it inserts!

Posted Image

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?

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Welcome to the evils of regional settings. You may have to call formatdatetime to get it into Access correctly.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
2710

2710

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Thank you it works now :D