Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
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:
  #1  
Old January 15th, 2004, 07: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, 09: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: 7
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, 03: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, 05:02 PM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 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 18 h 10 m 33 sec
Reputation Power: 500
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, 10: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, 04: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 04:21 PM.

Reply With Quote
  #7  
Old January 21st, 2004, 06: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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT