Solved

Changing values of boolean field of dataset with SQL

Posted on 2004-04-19
15
228 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 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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