Hi,
I have a field in my database that is 'Currency'. Now in delphi I have this code:
And example of FloattoStr(Price) = 2.4 for exampleCode: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;
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
What database type is this and table structure?
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
i have done some testing and I have realised that it is not the currency which is the problem, it is the 'Dates'
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?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;
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![]()
Try wrapping your date value in single quotes.
If I have that, it doesn't work, it gives me a 'Data Mismatch' error.Code:UPDATE Z1Read Set Books = 10 Where Dates = '21/03/2010'
Whereas if I had this:
It does work. Any ideas? The thing is, I need the first one.Code:UPDATE Z1Read Set Dates = '21/03/2010' Where Books = 10
It looks like you need to use # to delimit your date strings. Access Tips: Query and Filter Criteria
You are a legendTHANKS!!
![]()
Nah, I'm just good at Googling.
WHY? It works, but now its doing something stupid, Look:
This is just one form with one button which executes this codeCode: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;
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?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks