Solved

ado query

Posted on 2002-04-10
20
354 Views
Last Modified: 2013-11-23
I use two ado query in my form.the first is for querying.the next is for insert.the query component is linked to a datagrid component.
when I push the new button,I use the second ado query to execsql to insert an empty record.I set some default value to it.and then I close and open(also try the requery) the first ado query.but the data displayed in datagrid is still not having the new record.
does anyone can help me?
0
Comment
Question by:tzxie2000
  • 13
  • 5
  • 2
20 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6933246
can you show the queries and your code?
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933256

  with qryExec do
  begin
    Close;
    sql.Clear;
    NodeType := GetNodeType(TVAll.Selected);
    if (NodeType=NodeTypeGroupUP) then
    begin
      GroupINfo := TVAll.Selected.Data;

      sql.Add(Format('insert into RuleList(GroupID,UserID,SoftID,ModelID) values(%d,0,0,0)',[GroupInfo.GroupID]));
    end;
    if (NodeType=NodeTypeUserUP) then
    begin
      UserINfo := TVAll.Selected.Data;
      sql.Add(Format('insert into RuleList(GroupID,UserID,SoftID,ModelID) values(0,%d,0,0)',[UserInfo.UserID]));
    end;
    ExecSql;
    Close;
  end;
  with qryGroupRule do
  begin
    Close;
    Open;
    Requery;
  end;
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933259
the sql in qryGroupRule

 if (TSRuleGroupInfo = PCInfo.Pages[PCInfo.ActivePageIndex]) then
  begin
    NodeType := GetNodeType(TVAll.Selected);
    with qryGroupRule do
    begin
      Close;
      sql.Clear;
      if (NodeType = NodeTypeGroupUP) then
      begin
        GroupInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList ,SoftList ');
        sql.Add(Format('where (RuleList.SoftID<>0) and (RuleList.SoftID=SoftList.SoftID) and  (GroupID = %d) ',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList ,ModelList ');
        sql.Add(Format('where (RuleList.ModelID<>0) and (RuleList.ModelID=ModelList.ModelID) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,'''' as MN from RuleList');
        sql.Add(Format('where (RuleList.SoftID=0) and (RuleList.ModelID=0) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');
{        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList left join SoftList ');
        sql.Add(Format('on RuleList.SoftID=SoftList.SoftID where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList left join ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');}
      end;
      if (NodeType = NodeTypeUserUp) then
      begin
        UserInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN left join RuleList,SoftList ');
        sql.Add(Format('on (RuleList.SoftID=SoftList.SoftID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN left join RuleList,ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add(' Order by RuleID');
      end;
      Open;
      First;
    end;
    CBGroupExtend.OnClick(Nil);
  end;
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933297
the sql in qryGroupRule

 if (TSRuleGroupInfo = PCInfo.Pages[PCInfo.ActivePageIndex]) then
  begin
    NodeType := GetNodeType(TVAll.Selected);
    with qryGroupRule do
    begin
      Close;
      sql.Clear;
      if (NodeType = NodeTypeGroupUP) then
      begin
        GroupInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList ,SoftList ');
        sql.Add(Format('where (RuleList.SoftID<>0) and (RuleList.SoftID=SoftList.SoftID) and  (GroupID = %d) ',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList ,ModelList ');
        sql.Add(Format('where (RuleList.ModelID<>0) and (RuleList.ModelID=ModelList.ModelID) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,'''' as MN from RuleList');
        sql.Add(Format('where (RuleList.SoftID=0) and (RuleList.ModelID=0) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');
{        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList left join SoftList ');
        sql.Add(Format('on RuleList.SoftID=SoftList.SoftID where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList left join ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');}
      end;
      if (NodeType = NodeTypeUserUp) then
      begin
        UserInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN left join RuleList,SoftList ');
        sql.Add(Format('on (RuleList.SoftID=SoftList.SoftID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN left join RuleList,ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add(' Order by RuleID');
      end;
      Open;
      First;
    end;
    CBGroupExtend.OnClick(Nil);
  end;
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933298
the sql in qryGroupRule

 if (TSRuleGroupInfo = PCInfo.Pages[PCInfo.ActivePageIndex]) then
  begin
    NodeType := GetNodeType(TVAll.Selected);
    with qryGroupRule do
    begin
      Close;
      sql.Clear;
      if (NodeType = NodeTypeGroupUP) then
      begin
        GroupInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList ,SoftList ');
        sql.Add(Format('where (RuleList.SoftID<>0) and (RuleList.SoftID=SoftList.SoftID) and  (GroupID = %d) ',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList ,ModelList ');
        sql.Add(Format('where (RuleList.ModelID<>0) and (RuleList.ModelID=ModelList.ModelID) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,'''' as MN from RuleList');
        sql.Add(Format('where (RuleList.SoftID=0) and (RuleList.ModelID=0) and (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');
{        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN from RuleList left join SoftList ');
        sql.Add(Format('on RuleList.SoftID=SoftList.SoftID where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN from RuleList left join ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) where (GroupID = %d)',[GroupInfo.GroupID]));
        sql.Add(' Order by RuleID');}
      end;
      if (NodeType = NodeTypeUserUp) then
      begin
        UserInfo := TVAll.Selected.Data;
        Sql.Add('Select RuleList.* ,SoftList.SoftName as SN,'''' as MN left join RuleList,SoftList ');
        sql.Add(Format('on (RuleList.SoftID=SoftList.SoftID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add('union');
        Sql.Add('select RuleList.*,'''' as SN,ModelList.ModelName as MN left join RuleList,ModelList ');
        sql.Add(Format('on (RuleList.ModelID=ModelList.ModelID) and (UserID = %d)',[UserInfo.UserID]));
        sql.Add(' Order by RuleID');
      end;
      Open;
      First;
    end;
    CBGroupExtend.OnClick(Nil);
  end;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6933370
first guess,
the record is not shown because the select contains joins to other tables, where the record is not joinable

did you tried/verified the query with another frontend?
(usual with a query-tool which comes with your database)
(the requery-method should normally do the job)

meikl ;-)
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933389
I think the select may have a little problem.but not very sure.

but my problem is that when I try the new procedure the next time it will be ok and when I run program by step it will be also ok.
????
I try the delphi 5 and 6 .all are the same.

0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6933453
I think the select may have a little problem.but not very sure.

but my problem is that when I try the new procedure the next time it will be ok and when I run program by step it will be also ok.
????
I try the delphi 5 and 6 .all are the same.

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6933463
yep, thats mysterious
0
 
LVL 2

Expert Comment

by:header
ID: 6935882
Try doing a Post on the Query directly after doing the ExecSQL.

   ...
   ExecSql;
   Post;
   Close;
   ...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Author Comment

by:tzxie2000
ID: 6949914
when use execsql it can not post any data as it is not in edit mode.I try to add an edit before exesql,but it is still not correctly.
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6949935
when use execsql it can not post any data as it is not in edit mode.I try to add an edit before exesql,but it is still not correctly.
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6962280
could anyone help me?
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6974744
I have solved this problem myself.
let all the adoquery use the same connection can solve this problem
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6974772
well glad, you got it work,
never guessed that

ask a zero point q at community support for taking
this q into paq and refunding your points

meikl ;-)
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6976607
do you know how can I decreate the points?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6976633
? decreate points

what does you mean?
if you want to get back your points, which you've invested in this q, then ask a zero-point q at community support for getting this q into paq and refunding your points.

a moderator will pick up then the q

meikl ;-)
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6976638
do you know how can I decreate the points?
0
 
LVL 2

Expert Comment

by:header
ID: 6977418
kretzschmar has just told you:

-  Go to the Community Support page http://www.experts-exchange.com/commspt/

-  Post a new question (zero points) stating that you have answered your own question and want your points back as well as the question completed.

-  Make sure to include the link to this question somewhere in your post.
http://www.experts-exchange.com/delphi/Q.20287327.html

A moderator will then take over.
0
 
LVL 5

Author Comment

by:tzxie2000
ID: 6981601
No matter you or me solve the problem,thanks for your help.
0

Featured Post

What Is Threat Intelligence?

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

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

12 Experts available now in Live!

Get 1:1 Help Now