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, 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: 8
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 15th Plane (12000 - 12499 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 12,025 Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level)Memnoch User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 12 h 21 m 3 sec
Reputation Power: 628
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





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

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





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek