Link to home
Start Free TrialLog in
Avatar of ferhad
ferhadFlag for Azerbaijan

asked on

Changing values of boolean field of dataset with SQL

With the following code I am trying to change all records of Show field into False that matchs with to the following condition.

clientID :=5; contractNo := 10;

QuerySort.Active := False;
QuerySort.SQL.Text := 'UPDATE DEBTS SET Show=' + '''' + '''False''' + ''''
                              + ' WHERE (ClientID= IntToStr(clientID))and(ContractNo=contractNo)';
QuerySort.ExecSQL;

clientID and contractNo are the variables into which I am giving values above.
SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ferhad

ASKER

Esoftbg I have tested it and it gave me an error with message "No current record"
Avatar of ferhad

ASKER

Both codes kretzschmar yours and esoftbg yours woks but they are giving the same error. ("No current record")
Avatar of ferhad

ASKER

What should I do in order to prevent this error ?
do you try to open the query?
if so, then you must replace the statement with your
previous select-statement before opening

meikl ;-)
Avatar of ferhad

ASKER

No I am just executing it

const SQL = 'UPDATE DEBTS SET Show=False WHERE (ClientID= :ClientID) and (ContractNo=:contractNo)';

querysort.Active := False;
querysort.sql.text := SQL;
querysort.parambyname('ClientID').AsInteger := ClientID;
querysort.parambyname('contractNo').AsInteger := contractNo;
querysort.ExecSQL;

That's all what I am doing.
I am working with your Tables that you sent me by e-mail. It works fine here....
If you want I will send you above code by e-mail.
emil
Avatar of MikProg
MikProg

Long long ago when Delphi 2 was a yanger 'No current record' make mad many programmers who update records with a values that sends visual controls current record out of filter applayed by query or other datasets. So reopening of query AFTER update produces 'No current record'.
Is I'm right?
good point, mikprog
Avatar of ferhad

ASKER

Please, send it me esoftbg
MikProg but I am not reopenning my query component after update procedure.
MikProg means,
there may dataaware-controls attached via a TDatasource to the query,
which causes this problem
-> deAttach the Dataset from the Datasource before
-> DataSource1.Dataset := nil;

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ferhad

ASKER

I have found that two components simultaniously using the same dataset(TTable and TQuery). Before calling update method I closed Table. After execution of update I am calling Open method of table again. Now everything works. :)
just to ask about:
why a c-grade??