Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old January 15th, 2004, 06:02 PM
jodeman jodeman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 10 jodeman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sql query select

I want to select an item from a listbox, this query works fine and all fields of CLASS are present in the listbox. My problem is that I want to select a CLASS and get all the students from the selected class into another listbox. I get an error on data3.refresh, I think my error lies with that my datafield cant be refreshed. Here is the code
-

Private Sub lstClasses_DblClick()
Dim SQL As String
Dim amount As Integer
Dim help As String

help = lstclasses.Text

SQL = "Select STAMBOEKNR from STUDENTS Where CLASS Like " & help & " Order by 1"
Data3.RecordSource = SQL
Data3.Refresh

Data3.Recordset.MoveFirst
amount = Data3.Recordset.RecordCount

For i = 1 To aantal
lststamboek.AddItem (Text6.Text)
Data3.Recordset.Movenext
Next i
-

thanks!

Reply With Quote
  #2  
Old January 15th, 2004, 08:33 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
I see one problem with your sql query. Help is a string and needs single quotes:

SQL = "Select STAMBOEKNR from STUDENTS Where CLASS Like '" & help & "' Order by 1"

Reply With Quote
  #3  
Old January 17th, 2004, 02:51 PM
jodeman jodeman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 10 jodeman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
still doesnt work :-(

Reply With Quote
  #4  
Old January 17th, 2004, 04:02 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,738 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 h 41 m 10 sec
Reputation Power: 443
assuming you are using SQL Server.
since you are using the LIKE command you need to use the wildcard character with the statement, like this
Code:
For SQL Server
SQL = "SELECT stamboeknr FROM students WHERE class LIKE '%" & help & "%' ORDER BY 1"

Code:
For Access
SQL = "SELECT stamboeknr FROM students WHERE class LIKE '*" & help & "*' ORDER BY 1"


Depending on where you place the wildcard character in the statement determines what it searches for.

Code:
Returns everything where the fieldName BEGINS WITH the value passed
SELECT * FROM tableName WHERE fieldName LIKE '" & value & "%'

Code:
Returns everything where the fieldName ENDS WITH the value passed
SELECT * FROM tableName WHERE fieldName LIKE '%" & value & "'

Code:
Returns everything where the fieldName CONTAINS the value passed
SELECT * FROM tableName WHERE fieldName LIKE '%" & value & "%'

Reply With Quote
  #5  
Old January 19th, 2004, 09:43 AM
jodeman jodeman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 10 jodeman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It should always be the correct value, because its selected from a database. So I dont think the wildcard character is needed.

Reply With Quote
  #6  
Old January 20th, 2004, 03:15 PM
jodeman jodeman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 10 jodeman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I get all the items from STAMBOEKNR in my lisbox and not those whom I selected with the query, I can't find the problem. I use microsoft access database, no sql server.

Last edited by jodeman : January 20th, 2004 at 03:21 PM.

Reply With Quote
  #7  
Old January 21st, 2004, 05:06 PM
jodeman jodeman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 10 jodeman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i found it, it was a little mistake :-s. I used two names for the same string, help and hulp.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > sql query select


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway