Results 1 to 3 of 3

Thread: flexgrid and sql

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    23

    flexgrid and sql

    When I run 2 sql queries and return the result to flexgrid , I can only see data from the 2ns query and not the first,plz help
    VB Code:
    1. sql = "select count(*) as orders, date as jdate  from data where date between ' " & Format(Form1.dtp1.Value, "mm-dd-yyyy") & " ' and  ' " & Format(Form1.dtp2.Value, "mm-dd-yyyy") & " ' detail = 'order' group by date"
    2. rs1.Open sql, gcn, adOpenStatic, adLockOptimistic
    3. If rs1.RecordCount <> 0 Then
    4. rs1.MoveFirst
    5. Do While Not rs1.EOF
    6. sql1 = "insert into tmp(col1,col2) values (" & rs1("jdate") & "," & rs1("orders") & ")"
    7. rs2.Open sql1, con, adOpenDynamic, adLockOptimistic
    8. rs1.MoveNext
    9. Loop
    10. End If
    11.  
    12. sql2 = "select count(*) as torders, date as jdate from data where date between ' " & Format(Form1.dtp1.Value, "mm-dd-yyyy") & " ' and  ' " & Format(Form1.dtp2.Value, "mm-dd-yyyy") & " ' group by calldate"
    13. rs3.Open sql2, gcn, adOpenStatic, adLockBatchOptimistic
    14. If rs3.RecordCount <> 0 Then
    15. rs3.MoveFirst
    16. Do While Not rs3.EOF
    17. sql3 = "insert into tmp(col3) values (" & rs3("torders") & ")"
    18. rs4.Open sql3, con, adOpenDynamic, adLockOptimistic
    19. rs3.MoveNext
    20. Loop
    21. End If
    22.  
    23. rs2.Open "select * from tmp", con, adOpenStatic, adLockOptimistic
    24. Set MSHFlexGrid1.DataSource = rs2



    Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
    Last edited by Hack; Jul 26th, 2005 at 05:56 AM.

  2. #2
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: flexgrid and sql

    I think you are overlaying the results of the first recordset with the results of the second recordset.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: flexgrid and sql

    Your second loop should be UPDATEing the apropriate record in the temp table instead of INSERTing a new record.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width