Link to home
Start Free TrialLog in
Avatar of tzxie2000
tzxie2000Flag for China

asked on

ado query

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?
Avatar of kretzschmar
kretzschmar
Flag of Germany image

can you show the queries and your code?
Avatar of tzxie2000

ASKER


  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;
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;
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;
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;
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 ;-)
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.

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.

yep, thats mysterious
Avatar of header
header

Try doing a Post on the Query directly after doing the ExecSQL.

   ...
   ExecSql;
   Post;
   Close;
   ...
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.
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.
could anyone help me?
I have solved this problem myself.
let all the adoquery use the same connection can solve this problem
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 ;-)
do you know how can I decreate the points?
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you know how can I decreate the points?
kretzschmar has just told you:

-  Go to the Community Support page https://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.
https://www.experts-exchange.com/delphi/Q.20287327.html

A moderator will then take over.
No matter you or me solve the problem,thanks for your help.