Forum > Databases

[SOLVED} SQLite Zeos Update

<< < (2/5) > >>

Pe3s:
Thank you  :)

Pe3s:
Hi, I would like to implement a fix to update a record in SQLite + ZeosLib database, I mean is it possible to make the selection in DBGrid stay and the data will be updated?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button4Click(Sender: TObject);begin  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'UPDATE base SET Opis=:Opis, Link=:Link, Kategoria=:Kategoria, E-Mail=:E-Mail WHERE id=:id';  ZQuery1.ParamByName('Opis').AsString := LabeledEdit1.Text;  ZQuery1.ParamByName('Link').AsString := LabeledEdit2.Text;  ZQuery1.ParamByName('Kategoria').AsInteger := StrToInt(LabeledEdit3.Text);  ZQuery1.ParamByName('E-Mail').AsString := ComboBox1.Items[ComboBox1.ItemIndex];  ZQuery1.ParamByName('id').AsInteger := iId;  ZQuery1.ExecSQL;   ZQuery1.SQL.Text := 'SELECT * FROM base';  ZQuery1.Open;end;My code works but it reloads the whole database from scratch which selects the row from the beginning. How can I fix the code?

af0815:
If you deal with ExecSQL and Open the code is not fixable. if you write "ZQuery1.SQL.Text := 'SELECT * FROM base';" nobody can see your coloums. (And for me it is a nogo)

One way is to use the Query correct. Look for Query.Edit, Query.post, Query.delete,.... 

BTW: Read https://wiki.freepascal.org/SqlDBHowto and https://wiki.freepascal.org/Working_With_TSQLQuery

Pe3s:
Is this record update code correct?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  ZQuery1.Edit;  ZQuery1.FieldByName('Opis').AsString := LabeledEdit1.Text;  ZQuery1.FieldByName('Kategoria').AsString := LabeledEdit2.Text;  ZQuery1.FieldByName('E-Mail').AsString := LabeledEdit3.Text;  ZQuery1.Post;  ZQuery1.ApplyUpdates;  MessageDlg('Informacja','Zapisano zmiany!', mtinformation, [mbOK], 0);

af0815:
It looks correct, if the ID ( i think that is the primary key) is enclosed in the select statement and it is a simple table.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version