Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing values of boolean field of dataset with SQL

Posted on 2004-04-19
15
Medium Priority
?
238 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
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 80 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 70 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
Industry Leaders: 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 50 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

Independent Software Vendors: 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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

885 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