You are not logged in.
Pages: 1
This is the AddButtonClick procedure from you sample projects.
i want the sample to search for a record that may match the name entered and then update the record instead of adding the record at the end of the database.
1. i added sRec: TSQLSampleRecord to search the database for the old record.
2. if found, i want to update the datetime and the question.
3. The datetime is TModTime type, so i'm using sRec.Time := TimeLogNow; (which puts my computer time in db).
4. if Database.Add(Rec,true, false, true)=0 then //updates time correctly, the last true updates to my time i think.
5. if not Database.Update(sRec) then //DOES NOT UPDATE DATETIME CORRECTLY
note: i have tried Database.Update(sRec, [0..2]) and other updates, but can not get the update to change with my time.
Please advise how to code the update to update the question and time?
tks,
ted
//SAMPLE CODE FROM PROJECT
procedure TForm1.AddButtonClick(Sender: TObject);
var Rec, sRec: TSQLSampleRecord;
begin
Rec := TSQLSampleRecord.Create;
try
sRec := TSQLSampleRecord.Create(Database,'Name=?',[StringToUTF8(NameEdit.Text)]);
sRec.Name := StringToUTF8(NameEdit.Text);
sRec.Question := StringToUTF8(QuestionMemo.Text);
sRec.Time := TimeLogNow;
// we use explicit StringToUTF8() for conversion below
// a real application should use TLanguageFile.StringToUTF8() in mORMoti18n
Rec.Name := StringToUTF8(NameEdit.Text);
Rec.Question := StringToUTF8(QuestionMemo.Text);
Rec.Time := TimeLogNow;
if sRec.ID>0 then begin
if not Database.Update(sRec) then //DOES NOT UPDATE DATETIME CORRECTLY
ShowMessage('Error updating the data') else begin
NameEdit.Text := '';
QuestionMemo.Text := '';
NameEdit.SetFocus;
end;
end else
if Database.Add(Rec,true, false, true)=0 then //updates time correctly
ShowMessage('Error adding the data') else begin
NameEdit.Text := '';
QuestionMemo.Text := '';
NameEdit.SetFocus;
end;
finally
sRec.Free;
Rec.Free;
end;
end;
Offline
tks for the reply.
TTimeLog does update when used.
i have to handle datetime with daylight savings time. is TModTime a better way to handle daylight savings time. the values saved is 8 hours ahead of my local time. i am not sure what is meant by ServerTime?
tks for your help
ted
Offline
Pages: 1