Solved

Changing values of boolean field of dataset with SQL

Posted on 2004-04-19
15
230 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:ferhad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 40 total points
ID: 10866241
const SQL = 'UPDATE DEBTS SET Show=False WHERE (ClientID= :ClientID) and (ContractNo=:contractNo)';
begin
  querysort.Active := False;
  querysort.sql.text := SQL;
  querysort.parambyname('ClientID').AsInteger := ClientID;
  querysort.parambyname('contractNo').AsInteger := contractNo;
  querysort.ExecSQL;
end;

just from head

meikl ;-)
0
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 35 total points
ID: 10866428
procedure TForm1.Button3Click(Sender: TObject);
var
  ClientId:      Integer;
  ContractNo:    Integer;
begin
  ClientId := 63;
  ContractNo := 10;
  QuerySort.Active := False;
  QuerySort.SQL.Text := ''
                      + ' UPDATE DEBTS SET Show='
                      + '''' + 'False' + ''''
                      + ' WHERE (ClientID='
                      + '''' + IntToStr(clientID) + ''''
                      + ') and (ContractNo='
                      + '''' + IntToStr(ContractNo) + ''''
                      + ')'
                      + '';
  QuerySort.ExecSQL;
  QuerySort.SQL.Text := 'SELECT CalculatedPercent, CalculatedPercentAZM, Currency FROM DEBTS Where Show=True and Calcul=True';
  QuerySort.Active := True;
end;

emil
0
 
LVL 2

Author Comment

by:ferhad
ID: 10866515
Esoftbg I have tested it and it gave me an error with message "No current record"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:ferhad
ID: 10866550
Both codes kretzschmar yours and esoftbg yours woks but they are giving the same error. ("No current record")
0
 
LVL 2

Author Comment

by:ferhad
ID: 10866560
What should I do in order to prevent this error ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10866642
do you try to open the query?
if so, then you must replace the statement with your
previous select-statement before opening

meikl ;-)
0
 
LVL 2

Author Comment

by:ferhad
ID: 10866696
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.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10866707
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
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10866730
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?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10866835
good point, mikprog
0
 
LVL 2

Author Comment

by:ferhad
ID: 10866907
Please, send it me esoftbg
MikProg but I am not reopenning my query component after update procedure.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10866929
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;

0
 
LVL 3

Accepted Solution

by:
MikProg earned 25 total points
ID: 10867795
Hmm! I'm mistaken.
>>NO reopening of query AFTER update produces 'No current record'.
  ^^^^
Events follows as
1. Update query do job.
2. AutoRefresh poperty or other occurances (VCL & programmed by author) couses Query to refresh buffer for carrent record after update.
3. Internal method of Query object retrieves SINGLE record by finding her as directs UpdateMode property of Query object (I think you leave default value 'UpWhereAll' )
4. If record retrieved - values of visual controls will be refreshed (may be it is icorrect word in English, not in Delphi). If record missed - we have message ... right 'No current record'.

So
We need
or to disable autorefresh
or handle exception by reopening query (I prefer this)
or disable events cousing current record refresh (they are lot of them if you like hard work)

0
 
LVL 2

Author Comment

by:ferhad
ID: 10876791
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. :)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10876800
just to ask about:
why a c-grade??
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question