Solved

Changing values of boolean field of dataset with SQL

Posted on 2004-04-19
15
232 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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