Forum > Databases

TSQLQuery.ExecSQL not making changes

(1/11) > >>

HopefulGuy:
Okay, I'm sure I'm just missing something here. But I've read the docs and am at a loss.
I'm trying to make a form that displays a MariaDB record, and if I change the form and press the SAVE button it writes everything back to the record. So I tried something like this:

--- 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 TfrmData.btnSaveClick(Sender: TObject);  procedure SetField(FieldName: String; Data : String);  begin    Query.FieldByName(FieldName).AsString:=Data;  end;  procedure SetField(FieldName: String; Data: Integer);  begin    Query.FieldByName(FieldName).AsInteger:=Data;  end;begin  Query.Edit;  if (FrmMode = 'NEW') then    Query.SQL.Text:='inert into Table1 values (0, :Gender, :GivenName, :FamilyName, :Age,  :Email,  :Phone, :Postal)'  else  begin    Query.SQL.Text:='update Table1 set Gender=:Gender GivenName=:GivenName, FamilyName:=FamilyName, Age=:Age, , Email=:Email, Phone=:Phone, Postal=:Postal where IDNo=:IDNo';    SetField('IDNo', IDNo);  end;  setField('Gender', cbxGender.Text);  setField('GivenName', edtGiven.Text);  setField('FamilyName', edtFamily.Text);  setField('Age', StrToInt(trim(medtAge.text)));  setField('Email', edtEmail.Text);  SetField('Phone', edtPhone.text);  SetField('Postal', memPostal.Lines.Text);  Query.ExecSQL();  Query.Close();end; But when I go back and look at the actual database after I run this procedure, NOTHING HAS CHANGED.   Can anyone see what I did wrong?

Gustavo 'Gus' Carreno:
Hey HopefulGuy,

Could I, very politely, ask for you to use the code tags when putting code examples here?

Apart from the syntax highlighting, if and when you publish a bigger example, it will create a scrollable box that will be easier for anyone looking at your code AND your message at the same time.

Thank you very much in advance.

Cheers,
Gus

HopefulGuy:
Hopefully that fixed things for you.   :)

Gustavo 'Gus' Carreno:
Hey HopefulGuy,


--- Quote from: HopefulGuy on May 10, 2021, 07:26:45 am ---Hopefully that fixed things for you.   :)

--- End quote ---

Yes it did and thank you very much !!!!

Cheers,
Gus

Gustavo 'Gus' Carreno:
Hey HopefulGuy,

After looking at your code I have a question:

Why do you start your code with the variable Query and put it on Edit mode, but then use AsianLadiesQuery to execute the SQL?

Is this a copy/paste error?

Cheers,
Gus

Navigation

[0] Message Index

[#] Next page

Go to full version