Recent

Author Topic: (solved) can´t update a record in ms access table  (Read 2204 times)

Roque

  • New Member
  • *
  • Posts: 11
(solved) can´t update a record in ms access table
« on: October 17, 2014, 03:07:14 pm »
As I was unable to work with  mysql ... I am using an Access database (mdb), I connect via odbc component to ms access and I'm fetching  the data from a table using TSQLQuery.

I'm using a dbgrid, and when I change the contents of a field in the dbgrid, I can not update the table in the database.

I've tried several examples I have seen on the net, but I can not make this to work ... I know I'm doing something wrong .. but do not know where ...

TSQLQuery useprimarykeyaskey=false since odbc component don´t work with this .

in TSQLQuery  i have create the 4 parameters with the correct type , I had to put to false Paramcheck because it  always give me 0 count  heaven with the parameters created ... wtf ????

this is my TSQLQuery.UpdateSQL property "update emails set Numero=:Numero ,Nome=:Nome,email=:email where ID=:ID "

updatemode property is set to upWhereKeyOnly

this is my events on the TSQLQuery (SQLQryEmails)  .


procedure TDM.SQLQryEmailsAfterPost(DataSet: TDataSet);
var   
      cnt  :Integer;
begin
   cnt:=SQLQryEmails.Params.Count;
   SQLQryEmails.ApplyUpdates();

end;

procedure TDM.SQLQryEmailsBeforePost(DataSet: TDataSet);
begin

   SQLQryEmails.Params[0].AsInteger := DataSet.FieldByName('Numero').AsInteger;
   SQLQryEmails.Params[1].AsString := DataSet.FieldByName('Nome').AsString;
   SQLQryEmails.Params[2].AsString := DataSet.FieldByName('email').AsString;
   SQLQryEmails.Params[3].AsInteger := DataSet.FieldByName('ID').AsInteger;
end;

procedure TDM.SQLQryEmailsAfterEdit(DataSet: TDataSet);
begin

   SQLQryEmails.Params[0].AsInteger := DataSet.FieldByName('Numero').AsInteger;
   SQLQryEmails.Params[1].AsString := DataSet.FieldByName('Nome').AsString;
   SQLQryEmails.Params[2].AsString := DataSet.FieldByName('email').AsString;
   SQLQryEmails.Params[3].AsInteger := DataSet.FieldByName('ID').AsInteger;

end;
   
 note: already tried with SQLQryEmails.Params.ParamByName(....) , with same result .. none :(
  none of this works ... I'm getting nuts with this ....



« Last Edit: October 20, 2014, 12:55:35 pm by Roque »

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis

Roque

  • New Member
  • *
  • Posts: 11
Re: can´t update a record in ms access table
« Reply #2 on: October 20, 2014, 12:55:09 pm »
it worked thank you

 

TinyPortal © 2005-2018