|
-
Nov 6th, 2001, 10:32 AM
#1
Thread Starter
Lively Member
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.
-
Nov 6th, 2001, 11:24 AM
#2
Frenzied Member
VB Code:
'Declarations
Dim mstrPicture() as String
Private Sub Form_Load()
Dim i as Integer
Dim sql as String
Dim cn as New ADODB.Connection
Dim rs as New ADODB.Recordset
cn.Open("connectionstring")
sql = "select b.picture, b.description from table2 a " _
& " inner join table1 b on b.name = a.custname " _
& " order by b.description"
set rs = cn.Excecute(sql)
While Not rs.EOF
List1.AddItem rs!description
Redim Preserve mstrPicture(i)
mstrPicture(i) = rs!picture
i = i + 1
rs.MoveNext
Wend
End Sub
Private Sub List1_Click()
Picture1.Picture = mstPicture(List1.ListIndex)
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!

-
Nov 6th, 2001, 12:37 PM
#3
Lively Member
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
-
Nov 6th, 2001, 05:27 PM
#4
Frenzied Member
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!

-
Nov 7th, 2001, 06:56 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|