Solved

Changing values of boolean field of dataset with SQL

Posted on 2004-04-19
15
225 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now