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
Solved

ado query

Posted on 2002-04-10
20
358 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 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