Results 1 to 5 of 5

Thread: Need help with SQL

  1. #1

    Thread Starter
    Lively Member jalopez's Avatar
    Join Date
    Jul 2001
    Location
    Puerto Rico
    Posts
    108

    Unhappy Need help with SQL

    I read a few weeks ago a post in which someone published a link to a site that offered a SQL generator that uses english like language to produce a SQL query. I don't remember who published it, but, PLEASE I need that link now.

    I have to make a lot of queries using SQL SELECT statements and I do not have the time to use Access to generate buggy code and I neither have the time to guess the queries.

    -------------------------------------------------------------------------------
    The first query I need to produce should be able to get all the records from a table that contains images but the images should be of the same user. I mean:

    Table 1
    ------------------
    RecID
    CustName


    Table2
    -------------------
    RecID
    Name
    Description
    Picture


    Query Case:
    -------------------
    I need a query to get all the pictures from Table2 where the Table2.Name = Table1.CustName ordered by Table2.Description ASC.


    VB Case:
    ----------------
    When I get the pictures in the query, they should appear listed by description in a listbox, and when I click on a name in the listbox I should be able to see the picture in a imagebox. Only the images from the selected custommer should appear in the listbox.

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    VB Code:
    1. 'Declarations
    2. Dim mstrPicture() as String
    3.  
    4. Private Sub Form_Load()
    5. Dim i as Integer
    6. Dim sql as String
    7. Dim cn as New ADODB.Connection
    8. Dim rs as New ADODB.Recordset
    9.  
    10. cn.Open("connectionstring")
    11.  
    12. sql = "select b.picture, b.description from table2 a " _
    13.    & " inner join table1 b on b.name = a.custname " _
    14.    & " order by b.description"
    15.  
    16. set rs = cn.Excecute(sql)
    17.  
    18. While Not rs.EOF
    19.    List1.AddItem rs!description
    20.    Redim Preserve mstrPicture(i)
    21.    mstrPicture(i) = rs!picture
    22.    i = i + 1
    23.    rs.MoveNext
    24. Wend
    25. End Sub
    26.  
    27. Private Sub List1_Click()
    28.    Picture1.Picture = mstPicture(List1.ListIndex)
    29. End Sub
    This would assume that the full path to the picture is stored in the picture field.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3
    Lively Member
    Join Date
    Nov 2001
    Posts
    89
    Don't forget to close your recordset and connection objects and set the variables to nothing. It can cause you problems if you don't.

    Also, what does the array mstrPicture do for you? Won't this code work just as well without it?

    --KSW

  4. #4
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    The array saves all the file locations of the pictures based on the listindex of the description, so you don't have to go back to the database for each one. And obviously close your connections. I am just rattling this off here.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  5. #5

    Thread Starter
    Lively Member jalopez's Avatar
    Join Date
    Jul 2001
    Location
    Puerto Rico
    Posts
    108

    Wink Thanks!

    Thank you very much.

    I appreciate the time you have taken to answer this stupid question. Although this was not what I did it gave me a cool idea of what to do. Thanks.

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